Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

move_uploaded_file() or copy() not working...

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

move_uploaded_file() or copy() not working...

Postby LarryG » Fri Jul 11, 2003 9:49 am

I have recently switched virtual hosting environments. The former environment was FreeBSD and they had php version 4.0.? running. I was able to successfully upload files with the copy() function. The new hosting service has Linux, Apache 1.3.27, php 4.3.2. The copy() function fails in this environment. I have the same versions of apache and php running on my windows xp prof machine and the copy() function works there.

Are there environment settings that might be causing my problem? I am attempting to upload image files that are much less than the 2meg limit and am trying to copy to a directory that is chmod 755. The php.ini has file_upload on and upload_max_size = 2m.

Form sending file:
<FORM ACTION="./AddAResp.php" METHOD=POST ENCTYPE="multipart/form-data">
.
.
.
<INPUT TYPE=FILE NAME="userfile" SIZE=25 MAXLENGTH=60>
.
.

Form Handler in same directory:
//Need to upload Auction Sale Bill file then insert the Auction Notice
if($userfile > '!')
{
if($userfile_type == 'application/pdf')
{
$filetype = ".pdf";
}
else
{
$filetype = ".html";
}
$SaleBill = str_replace(".", " ", $AuctionDatesFRM);
$SaleBill = str_replace(",", " ", $SaleBill);
$SaleBill = str_replace("$", " ", $SaleBill);
$SaleBill = str_replace(" ", "", $SaleBill);
$SaleBill .= $filetype;
$picfile = "../images/";
$picfile .= $SaleBill;

if(move_uploaded_file($userfile, $picfile))
{
echo "<br>$picfile was uploaded successfully";
}
else
{
echo "<br>$picfile was not uploaded!";
}

Any help will be greatly appreciated.

LarryG
LarryG
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Jul 11, 2003 9:31 am

Postby pootergeist » Sun Jul 13, 2003 4:24 am

do you have register_globals OFF ?

if so you would need to access the variables through the $_FILES array eg

$_FILES['userfile']['tmp_name']
$_FILES['userfile']['type']
$_FILES['userfile']['name']
$_FILES['userfile']['size']
$_FILES['userfile']['error']
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

move_uploaded_file() or copy() not working...(continued)

Postby LarryG » Mon Jul 14, 2003 2:39 am

Thanks Pootergeist for the help with the $_FILE suggestion.

Register_Globals is on, but I revised my script to avoid problems if the ISP/Hosting Service turns it off.

I now access the file to upload (userfile) as follows:

extract($_FILES['userfile'], EXTR_PREFIX_ALL, 'uf');
if($uf_type == 'application/pdf')
{
$filetype = ".pdf";
}
else
{
$filetype = ".html";
}
$SaleBill = str_replace(".", " ", $AuctionDatesFRM);
$SaleBill = str_replace(",", " ", $SaleBill);
$SaleBill = str_replace(" ", "", $SaleBill);
$SaleBill .= $filetype;
$picfile = "../images/";
$picfile .= $SaleBill;
copy($uf_name, $picfile);


The copy still isn't working. I'm not sure what is happening at the host and I don't know how to access an error msg to help debug it.



LarryG
LarryG
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Jul 11, 2003 9:31 am

Postby pootergeist » Mon Jul 14, 2003 2:44 am

try

move_uploaded_file($uf_tmp_name, ..whereever..);

the variable $uf_name should hold the client name and not the pointer to the tmp version.
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

Postby LarryG » Mon Jul 14, 2003 7:03 am

Okay, that was not very bright of me. Thanks for catching it. I've modified the move_uploaded_file to test for true or false:

if(move_uploaded_file($uf_tmp_name, $picfile))
{
echo "<br>$picfile was uploaded successfully";
}
else
{
echo "<br>$picfile was not uploaded!";
}


The move_uploaded_file() is returning false, how can I determine what caused the failure? Is there an error logged somewhere or an errormsg that I can access or print when the move_uploaded_file() function returns a false?

LarryG
LarryG
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Jul 11, 2003 9:31 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.