Forum Moderators: coopster
Any help will be appreciated. Thanks
if (is_uploaded_file($HTTP_POST_FILES['fileupload']['tmp_name'])) {
if (is_file($path.$SOQname)) unlink($path.$SOQname);
if (move_uploaded_file($HTTP_POST_FILES['fileupload']['tmp_name'], $path.$SOQname)) {
$message = '<strong>New SOQ uploaded.</strong><br>';
} else {
$message = '<strong>uploaded but not moved to the correct folder.</strong><br>';
};
} else {
$message = '<strong>not uploaded.</strong><br>';
};
If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will returnFALSE.If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return
FALSE. Additionally, a warning will be issued.
Make sure error_reporting [php.net] is turned up and you aren't getting any messages.
Two other things I note. First, the old $HTTP_POST_VARS array, although still available, has been deprecated. You should really start using the new superglobals [php.net]. Second, I always like to incorporate the $_FILES error array during an upload. It will offer you the ability to tell your end user exactly why a file upload error occurred in a nice message you can format yourself and it makes it a lot easier to edit check and troubleshoot a file upload script.
error_reporting(9) is set. No error message.
this is the $HTTP_POST_FILES
Array ( [fileupload] => Array ( [name] => 02.jpg [type] => image/pjpeg [tmp_name] => C:\PHP\uploadtemp\php328.tmp [error] => 0 [size] => 24892 ) )
this is the $_FILES
Array ( [fileupload] => Array ( [name] => 02.jpg [type] => image/pjpeg [tmp_name] => C:\PHP\uploadtemp\php328.tmp [error] => 0 [size] => 24892 ) )
I do not think that the problem is because of using HTTP_POST_FILES and not FILES because I am able to upload the file the first time but not second time. I believe that there is something to do with file permissions and not being able the move_uploaded_file to move the file.
Do you know some *working* way to delete a file under windows, as unlink does not work?
I tried system("del filename") but still no luck :(
Vevs
error_reporting(9) is set. No error message.
There will be no warning error messages displayed as that setting is too low. E_WARNING is a level 2 and you are at 9 which is
E_ERROR ¦ E_NOTICE, which is to say (1¦8). I highly recommend reporting ALL errors in a development environment as it aids in troubleshooting [webmasterworld.com]. Don't forget to turn all errors off when promoting to your live server though.
Yes, even though both the superglobal and HTTP_*_VARS can exist at the same time and are indeed going to contain the same thing I'm just letting you know that the old HTTP_*_VARS are deprecated which means you should get in the practice of using the new superglobals.
Lastly, since your $_FILES['error'] value is returning '0' it seems your upload is working fine so indeed it is in the moving of the file that your troubles start.
Crank up the error_reporting to see what kind of message you are getting.
Warning: unlink(D:\users\*****\SOQ_web.jpg) [function.unlink]: Permission denied in D:\users\fecontracting.com\admin.php on line 33
Warning: move_uploaded_file(D:\users\*****\SOQ_web.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\users\fecontracting.com\admin.php on line 34
I am trying to chmod (checking via FTP is says the permission is 777) and actually I do not think chmod works under windows anyway :)
any other ideas?
First, are you sure the path and filename look correct as dreamcatcher asked? Dump them to your browser to be sure, and pay close attention to the DIRECTORY_SEPARATOR to make sure it looks like a WINDOWS directory separator. Make sure this directory and path exist, too. After you dump the value to your browser, cut and paste the directory into a windows explorer address to make sure you can navigate to it.
If that all checks out then you might try testing by running the server as an admin to see if that resolves the issue. If this does it, then you certainly have a Windows OS permissions issue.