Ninjakreborn Posted September 19, 2006 Share Posted September 19, 2006 This isn't working, I want to test to see if they tried to upload a file, if they did, then I want to do some validation on the file, and then try to move it, check to make sure it exists, whatever. BUt I only want to do that stuff if they tried to upload a file, because the file upload is optional, it's not required?? But when I test for the files variable before working on it, and don't upload a file, it still tries to work on the non-existent file, that would lead me to assume that the files array already has something stored in it, whether a file has been uploaded into memory or not, so how do I test to see if they attempted one. because they can attempt an upload, and it not upload, so I still need to check forif (!is_uploaded_file) {$errorhandler .= "You file was not uploaded properly";}that is one of the things I need to test for, but I don't want to test for that, unless they attempted to upload one and it failed, not jsut if they didn't want to upload one in the first place[code]<?phpif ($_FILES) { $newfile = "uploads/".basename($_FILES['file']['name']); $newfiletemp = "{$_FILES[file][tmp_name]}"; if (file_exists($newfile)) { $errorhandler .= "The file already exists"; }if (!move_uploaded_file($newfiletemp, $newfile)) { $errorhandler .= "There was some sort of problem moving the file"; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21280-files-if-they-tried-to-upload-a-file-work-with-file-if-they-didnt-dont/ Share on other sites More sharing options...
zq29 Posted September 19, 2006 Share Posted September 19, 2006 I use one of two methods, first off is to check if $_FILES['userfile']['name'] is empty, or check what $_FILES['userfile']['error'] is set to, if it is set to '4', the user did not select a file to upload. Quote Link to comment https://forums.phpfreaks.com/topic/21280-files-if-they-tried-to-upload-a-file-work-with-file-if-they-didnt-dont/#findComment-94661 Share on other sites More sharing options...
Ninjakreborn Posted September 19, 2006 Author Share Posted September 19, 2006 Ok I got it, but I am running into another problem.Here is my code for reference[code]<?php // file handling if ($_FILES['notefile']['name']) { $newfile = "./uploads/notesandcheatsheets/".basename($_FILES['notefile']['name']); $newfiletemp = "{$_FILES[notefile][tmp_name]}"; if (file_exists($newfile)) { $errorhandler .= "The file already exists"; } if (!move_uploaded_file($newfiletemp, $newfile)) { $errorhandler .= "There was some sort of problem moving the file"; } }else { $newfile = "No file was uploaded"; $newfiletemp = "No file was uploaded"; } // end file handling?>[/code]Ok there is the code, the problem I am having is it's not moving the file. THe script that I am running for this is on a processor from the root folder it's from /processors/post4.phpNow the file is being upload(from the root directory) to the following file/uploads/notesandcheatsheets/for some reason it's not moving it, I am saving the newfile and newfiletemp variables into the database, the newfile being the url, and hte newfiletemp being the name.The thing is, it's not uploading, and I also need to make sure I can access the file later when calling the fileurl from the database. So what do I need to do in this situation, and why isn't it working like this?Also for the newfile variable, where I am setting the url, I tried a few thingsI tried/uploads/notesandcheatsheets./uploads/notesandcheatsheetsbut nothing seems to be allowing me to move the file. Quote Link to comment https://forums.phpfreaks.com/topic/21280-files-if-they-tried-to-upload-a-file-work-with-file-if-they-didnt-dont/#findComment-94686 Share on other sites More sharing options...
SharkBait Posted September 19, 2006 Share Posted September 19, 2006 Is it coming back to you with an error?Make sure your permissions on the directory you're moving the file too is correct as well as the file executing the move_uploaded_file(). Quote Link to comment https://forums.phpfreaks.com/topic/21280-files-if-they-tried-to-upload-a-file-work-with-file-if-they-didnt-dont/#findComment-94692 Share on other sites More sharing options...
Ninjakreborn Posted September 19, 2006 Author Share Posted September 19, 2006 I checked permissions, that wasn't the problem.I noticed a few issues, I had some of the folders named wrong so I fixed those. ANd it is not 100% pointing to the right path, I am using this code below, and below that is the error it's giving me.[code]<?php // file handling if ($_FILES['notefile']['name']) { $newfile = "/upload/notesandcheatsheets/".basename($_FILES['notefile']['name']); $newfiletemp = "{$_FILES[notefile][tmp_name]}"; if (file_exists($newfile)) { $errorhandler .= "The file already exists"; } if (!move_uploaded_file($newfiletemp, $newfile)) { $errorhandler .= "There was some sort of problem moving the file"; } }else { $newfile = "No file was uploaded"; $newfiletemp = "No file was uploaded"; } // end file handling?>[/code]Here is the error message below[quote]Warning: move_uploaded_file(/upload/notesandcheatsheets/access information.txt): failed to open stream: No such file or directory in /home/content/b/c/h/bcharnas/html/processors/post4.php on line 272Warning: move_uploaded_file(): Unable to move '/tmp/php4SyVSd' to '/upload/notesandcheatsheets/access information.txt' in /home/content/b/c/h/bcharnas/html/processors/post4.php on line 272There was some sort of problem moving the file [/quote] Quote Link to comment https://forums.phpfreaks.com/topic/21280-files-if-they-tried-to-upload-a-file-work-with-file-if-they-didnt-dont/#findComment-94704 Share on other sites More sharing options...
Ninjakreborn Posted September 19, 2006 Author Share Posted September 19, 2006 got it, thanks Quote Link to comment https://forums.phpfreaks.com/topic/21280-files-if-they-tried-to-upload-a-file-work-with-file-if-they-didnt-dont/#findComment-94717 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.