Page 2 of 2
Posted: Mon Mar 22, 2004 10:35 am
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
Posted: Mon Mar 22, 2004 10:39 am
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.
Posted: Mon Mar 22, 2004 10:43 am
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();
}
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
Posted: Mon Mar 22, 2004 10:47 am
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']))
Posted: Mon Mar 22, 2004 10:49 am
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
Posted: Mon Mar 22, 2004 10:53 am
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.
Posted: Mon Mar 22, 2004 10:55 am
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.
Posted: Mon Mar 22, 2004 11:01 am
by mjseaden
Hi McGruff - can you clarify what your code does?
Thanks
Mark
Posted: Mon Mar 22, 2004 11:09 am
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.