Hi i'm trying to upload a picture to the server using a form and it all seems to be working fine the only problem is I can't seem to find the picture when its uploaded, the script runs fine and gives me no errors and then when I come to look in the folder where i think it should be, there is nothing there. I'm using a test environment on the mac and am using the inbuilt apache server on OSX but don't have any idea which is the root folder as far as the move_uploaded_file function is concerned:

$destination = "upload/";
move_uploaded_file($_FILES["pix"]["tmp_name"], $destination.$_FILES["pix"]["name"]);
echo "br />Moved to: " .$destination.$_FILES["pix"]["name"];

This is the offending code, now I would assume that the file would be in a folder called upload on the mac HD, anyone know where i'm going wrong!?

Cheers.

Recommended Answers

All 8 Replies

use the actual path /path/to/your/html/upload

Sorry, realise I'm being amazingly thick here but just can't get my head around this, can someone explain this as if explaining to an idiot....which, come to think of it, is exactly you are doing!!!

Cheers

Member Avatar for fatihpiristine

define full path
C:/websites/mysite/upload/

Right am thoroughly tearing my hair out on this one, thanks to you guys so far for your help, but I have a feeling there is something else happening apart from my inability to work out addressing properly, heres the full code,

$destination = '/upload/'.$_FILES["pix"]["name"];
echo $_FILES["pix"]["tmp_name"];
if(move_uploaded_file($_FILES, $destination))
{
echo "br />Moved to: ".$destination;
}
else
{
echo "Not working fool".$destination;
}

I am using apache and php 5 on localhost, that is they are installed on my mac and i'm running the upload program through the webserver folder. I have created a folder on the mac HD called 'upload' but can't get the thing to work...any ideas.

I think what people are trying to tell you is that you need to replace,

$destination = "upload/";

with

$destination = $_SERVER."/upload/";

That should fully specify your local path to the destimation directory.

You may also be running into problems trying to to this on a Mac. It might not work the same as on a Unix/Linux server.

Thanks for all your help guys finally figured it out to be a problem with permissions I had them set to read rather than write on the folder i wanted the files moved to.

Once again cheers!!

It's usually a good idea to add the following to the top of any PHP script that you are troubleshooting.

error_reporting(E_ALL);

You would have seen the permissions issue right away.

But it is not a good idea to leave that statement active on a script on a production site.

Ahhh, now I see how easy that could have been!!

Cheers,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.