Forum Moderators: coopster

Message Too Old, No Replies

How to specify the destination directory for a file uploaded by PHP?

         

irock

9:50 am on Jun 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Someone gave me this part so I can store an image resided on another server. So, my question is how I can specify the destination directory for my uploaded file?

$fp = @fopen($storelogo,'r') or die("Can not open image : $storelogo");

$localimage = basename($storelogo);//local image will have same name as image being uploaded.
$fp_new = fopen($localimage,'w');

if($fp)
{
while(!feof($fp))
{
$contents = fread($fp,4096);
fwrite($fp_new,$contents);
}
fclose($fp);
fclose($fp_new);
}

Thanks for any assistance.

till7

9:59 am on Jun 16, 2003 (gmt 0)

10+ Year Member



if $storelogo is the is the incoming file through a form, you can just copy ist to a directory you like with:
move_uploaded_file($storelogo, 'mydirectory/newname');

irock

10:09 am on Jun 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, $storelogo is only a URL... [domain.com...]

jatar_k

2:01 pm on Jun 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



this is your path irock

$fp_new = fopen($localimage,'w')

you are opening a file pointer to the place on your server you want the image to go. Maybe try this

$localimage = basename($storelogo);
$newimgpath = "/path/to/image/" . $localimage;
$fp_new = fopen($newimgpath,'w');

irock

2:48 pm on Jun 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks! But I also found out I need to add @ to this line for this to work.

$fp_new = @fopen($localimage,'w')

Not sure what @ is.

jatar_k

3:25 pm on Jun 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



@ suppresses warnings/errors from the function