Forum Moderators: coopster
Warning: move_uploaded_file(/upload/csv.csv): failed to open stream: No such file or directory in /home/roguedog/public_html/upload_file.php on line 6
Warning: move_uploaded_file(): Unable to move '/tmp/phpUP3Dxe' to '/upload/csv.csv' in /home/roguedog/public_html/upload_file.php on line 6
Could not upload file.
Here's the script:
<?
if(userfile=="none") {
echo "No file specified";
exit;
}
if (move_uploaded_file($userfile,"/upload/".$userfile_name)) {
echo "Your file has been uploaded.";
}else{
echo "Could not upload file.";
}
?> I've tried chmod the directory permissions, I've tried moving the files to another directory...same errors...any idea what it's puking on?
Seriously, I have written file upload stuff soooooooo many times I feel I could debug this in my sleep if you give me the original $_GET or $_POST variable to query to get the file itslf.
html form:
<html>
<head>
<title>File Upload</title>
</head><body>
<h2>Upload</h2>
<form enctype="multipart/form-data" action="upload_file.php" method="post">
<input type="hidden" name="max_file_size" value="2000000">
Filename:
<input name="userfile" type="file">
<br>
<br>
<input type="submit" value="Send">
</form>
</body>
</html>
php script:
<?
if(userfile=="none") {
echo "No file specified";
exit;
}
if (move_uploaded_file($userfile,"/upload/".$userfile_name)) {
echo "Your file has been uploaded.";
}else{
echo "Could not upload file.";
}
?>
I have both files located in a directory on my server /public_html/upload
and I have tried them in the root directory, both times with the same error as previously posted. Thanks for your help all...I'm pulling my last few hairs out of my head on this one. ( nooby here remember ) :)
<?
$userfile = $_POST['userfile']['name'];
if(!$userfile)
{
echo "There was no file supplied.<br>";
exit;
}
$where= $_SERVER['DOCUMENT_ROOT']."/uploads/";
$upload = $where.$userfile;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $upload))
{
echo "We have successfully uploaded a file.<br>";
}
else
{
echo "File upload failed for the following reasons: <br>";
print_r($_FILES);
}
?>
NEW ERROR: There was no file supplied
I tried putting the submit_file.html and upload_file.php in the /public_html directory and in /public_html/upload directory. Same error.
I also tried several file formats to upload incase, .csv, .txt....same error...ARGH
I really do appreciate all your help on this, that is keeping me sane... :)
<?
$userfile = $_POST['userfile']['name'];
echo "The userfile is: ".$userfile."<br>";$where= $_SERVER['DOCUMENT_ROOT']."/uploads/";
echo "The directory path uploading to is:".$where."<br>";
$upload = $where.$userfile;
echo "The path and file combined is: ".$upload."<br>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $upload))
{
echo "We have successfully uploaded a file.<br>";
}
else
{
echo "File upload failed for the following reasons: <br>";
print_r($_FILES);
}
?>
Let me know what the output for that is.
The userfile is:
The directory path uploading to is:/home/roguedog/public_html/uploads/
The path and file combined is: /home/roguedog/public_html/uploads/
Warning: move_uploaded_file(/home/roguedog/public_html/uploads/): failed to open stream: Permission denied in /home/roguedog/public_html/upload/upload_file.php on line 10
Warning: move_uploaded_file(): Unable to move '/tmp/php2KrUpt' to '/home/roguedog/public_html/uploads/' in /home/roguedog/public_html/upload/upload_file.php on line 10
File upload failed for the following reasons:
Array ( [userfile] => Array ( [name] => test.txt [type] => text/plain [tmp_name] => /tmp/php2KrUpt [error] => 0 [size] => 3824 ) )
After noticing the uploads vs upload issue, I changed the folder name to uploads and this is the error I got:
The userfile is:
The directory path uploading to is:/home/roguedog/public_html/uploads/
The path and file combined is: /home/roguedog/public_html/uploads/
Warning: move_uploaded_file(/home/roguedog/public_html/uploads/): failed to open stream: Is a directory in /home/roguedog/public_html/uploads/upload_file.php on line 10
Warning: move_uploaded_file(): Unable to move '/tmp/php5I29lE' to '/home/roguedog/public_html/uploads/' in /home/roguedog/public_html/uploads/upload_file.php on line 10
File upload failed for the following reasons:
Array ( [userfile] => Array ( [name] => test.txt [type] => text/plain [tmp_name] => /tmp/php5I29lE [error] => 0 [size] => 3824 ) )
BTW, the folder is set to 777 so that shouldn't be the issue.
It doesn't exactly seem to be catching the "userfile" name. That seems to be a sticking point cause if it didn't know the name of the file, how could it move it...maybe?
There are issues with move_uploaded_file() and safe mode being enabled, but I`m not sure thats a problem here.
dc
The possible errors that cause this are:
the file you're uploading is empty.
the form sending the data isn't the right enctype.
you're getting the wrong variable name
you're using $_POST instead of $_FILES
Until you get some sort of response appearing in the 'userfile is: ' line nothing is going to work.