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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload File Problem

Status
Not open for further replies.

RobHudson

Programmer
Apr 30, 2001
172
GB
I am trying to copy a file from a local machine to a webserver using copy(). When the script is run locally it works fine, but since it has been put on the webserver it fails with the following warning:

Warning: Unable to open 'C:\Clients\MTS\Course Data\WebSync XML\upload_q_headers.xml' for reading: No such file or directory in /htdocs/test/websync/rob_upload_xml.php on line 27

Does anyone have any ideas on the mistake that I am making??

Here's the code:

//Copies [uploads] the given xml file to the web server
//This requires a query string of file_name, web_location and file_location to be passed through
$web_location = "/htdocs/test/websync/";
$file_location = "C:\\Clients\\MTS\\Course Data\\WebSync XML\\";
$file_name = "upload_q_headers.xml";

//Set the script time out to never timeout
//Allows for script taking longer than 30 secs [or whatever the php default is]
set_time_limit(0);

//Establish local and web locations
$local_file = $file_location.$file_name;

//Upload the file
if (!copy($local_file, $web_location))
echo "Didn't work!";
else
echo "Worked!";

Help me!!
 
The browser uses a user to run. Does it has priviledges to enter all of the dirs in the path and to read the file?

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
I assume th browser uses the user that I am logged on as...if so I am on as administrator - in which case it does have permissions to that directory [or at least that local directory]...

Could it be a php.ini problem??
 
no ... the IIS runs, by default, as a user implicity created by him. It should be something like IUSR_MACHINENAME.
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
It seems as if you are trying to copy a file from your computer to the webserver with the copy function, which of course would fail since there is no upload. You would have to create a form and upload the file via that form. //Daniel
 
You've hit the nail on the head there Daniel - thanks ;)

Doing this works:

<?
function handleupload()
{
if (is_uploaded_file($_FILES['userfile']['tmp_name']))
{
$filename = $_FILES['userfile']['tmp_name'];
print &quot;$filename was uploaded successfuly<br>&quot;;

$realname = $_FILES['userfile']['name'];
print &quot;realname is $realname<br>&quot;;

print &quot;copying file to uploads dir<br>&quot;;

copy($_FILES['userfile']['tmp_name'], $web_location.$realname);
}
else
{
echo &quot;Possible file upload attack: filename &quot;.$_FILES['userfile']['name'].&quot;.<br>&quot;;
}
}
?>

<html>
<body>

<?
if ($act == &quot;upload&quot;) {
handleupload();
}
?>

<form ENCTYPE=&quot;multipart/form-data&quot; method=&quot;POST&quot; action=&quot;test_upload.php?act=upload&quot; name=&quot;fMain&quot;>
File:<INPUT TYPE=&quot;FILE&quot; NAME=&quot;userfile&quot; SIZE=&quot;35&quot;>
<input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;1000000&quot;>
<input type=&quot;submit&quot; value=&quot;Upload&quot; name=&quot;B1&quot;>
</form>
</body>
</html>

Thank you all for your help...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top