Array() error being generated from file_exists()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Hi wayne

I transferred the code, but it's still giving me the same error.

Maybe I should just try uploading using the FTP functions straight away and forget about using file_exists. It would however be useful to know what's going on here.

Also, what is the significance of tmp_name? I haven't defined this myself explicitly - is this automatically generated by the INPUT control as a temporary upload location before relocating to the permanent path?

Cheers

Mark
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

the tmp_name is the filename that the server issues to the file when it is uploaded to the server and before it is copied or delt with by your script. The file is only store as a temp file until you tell the server what you want to do with it.

post that bit of you code again and tell us what the current error message is.
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

The code again:

Code: Select all

// Do checks on local files to make sure filenames are valid and exist
	if(file_exists($_POSTї'photo1_upload']ї'tmp_name']))
    {
       //then the file exists code here! place code here
    }
    else
    {
       echo 'Cannot locate file for photo 1. Please make sure you have entered the correct filename and path for photo 1. Click <A HREF="XXXX.php?p=22"><FONT COLOR="#FFFFFF">here</FONT></A> to return to the data form.';
        exit();
    &#125;
And I'm getting the custom error:
Cannot locate file for photo 1. Please make sure you have entered the correct filename and path for photo 1. Click here to return to the data form.
The filename is D:\\BreakXL7.mp3, which I have check is safely located on my harddrive.

Thanks for doing this.

Mark
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

try changing

Code: Select all

if(file_exists($_POST['photo1_upload']['tmp_name']))
to

Code: Select all

if(is_uploaded_file($_POST['photo1_upload']['tmp_name']))
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Hi Wayne

I think the situation needs to be clarified a bit. I haven't uploaded these files yet - they're on my hard drive.

I want to use file_exists to check that the files the user has selected on the data form on the previous page exist where they say they are. Once I've checked they exist (the source), I then want to upload them to my site's FTP server (the destination). They haven't been uploaded yet.

Does that help clarify the problem a bit more?

Thanks again

Mark
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

if you are posting an HTML form that has a an INPUT type of file then the file is uploaded to the server this is why the tmp_name is created what you do with it after that is up to you. If you are talking about just writing a file name of a file on a computer that is viewing your site via a browser you cant check the machine for the file with php. the is_uploaded_file will check that for you if the person submits a form with a file selected the server will check that the file was actually uploaded to the server otherwise it will fail. PHP is serverside and cannot check infomation or files on a computer using a browser.
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

So file_exists can't check files on the client side...actually that makes sense considering PHP is a server side language.

Thanks for the help Wayne, much appreciated.
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Hi McGruff - can you clarify what your code does?

Thanks

Mark
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Scuse me I deleted that as soon as I posted - thought the problem was solved and it was no longer relevant.

print_r($_POST) lets you check what values you've got in the post array. <pre> tags make it easier to read a large array.
Post Reply