Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems uploading - "No such file or directory"

Status
Not open for further replies.

groovygarden

Programmer
Aug 23, 2001
63
Hi,

I'm trying to write code to let users upload a file to my server.

The form I use is like this:
Code:
<form enctype=&quot;multipart/form-data&quot; action=&quot;/admin/preview.php&quot; method=&quot;post&quot; name=&quot;add&quot;>
  <input name=&quot;MAX_FILE_SIZE&quot; type=&quot;hidden&quot; value=&quot;1000&quot;>
  <P>Upload File<br>
     <input name=&quot;testfile&quot; type=&quot;file&quot; size=&quot;40&quot;>
  </P>
  <input name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Submit&quot;>
</form>

I process the data like this:
Code:
if(!empty($testfile)) { 

    //copy the file to permanent location 
    copy($testfile, &quot;\files\myfile.txt&quot;); 

    //destroy the file 
    unlink($testfile); 
}

Pretty basic, but I just wanted to see if it would work... it didn't! I get this error message when trying to process the form:

Code:
Warning: Unable to open 'C:\PHP\uploadtemp\php26.tmp' for reading: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\admin\preview.php on line 14

Any ideas as to what (probably really obvious thing) I'm doing wrong?

Thanks a lot
 
Hi,

Line 14 is

Code:
copy($testfile, &quot;\files\myfile.txt&quot;);

where i try to copy $testfile to a permenant location. I also get the same error when I use unlink:
Code:
unlink($testfile);

The only variable I'm setting is $testfile and that comes from the form...
 
when using copy or unlink function use variable $testfile_name(The original name of the file) instead of only $testfile..

so ur line 14 shd be

copy($testfile_name, &quot;\files\myfile.txt&quot;);

also if ur unlinking u also have to use variable $testfile_name ..
ie
unlink($testfile_name);

spookie



--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Last time I checked, the [tt]name[/tt] variable held the name that the file had at the client. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top