3raser Posted January 13, 2011 Share Posted January 13, 2011 Why does it give me the "There was an error uploading the file, please try again!" error message? I've checked through the code, and I've looked to see what is wrong. I'm thinking it MIGHT be because of: $target_path = $target_path . $output; if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip") { if(move_uploaded_file($output, $target_path)) { But, heres the full code: <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } else { echo "<a href='start_upload.php'>Upload</a> | <a href='search.php'>Search & Browse</a> | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>"; $description = $_POST['description']; $description = mysql_real_escape_string($description); $ip = $_SERVER['REMOTE_ADDR']; $date = date('m-d-y'); $title = $_POST['title']; $title = mysql_real_escape_string($title); $user = $_SESSION['SESSION']; $target_path = "mods/"; $query = mysql_query("SELECT COUNT(id) FROM mods"); $finish_query = mysql_fetch_assoc($query); $output = $finish_query['COUNT(id)'] + 1; $target_path = $target_path . $output; if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip") { if(move_uploaded_file($output, $target_path)) { echo "The mod ". basename($_FILES['file']['name']) . " has been uploaded. Check it out <a href='mods/". $output ."'>HERE.</a>"; mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')"); } else{ echo "There was an error uploading the file, please try again!"; } } else { echo "You cannot use a .". pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION) ." extension! .zip is currently the only file extension allowed."; } } include("includes/footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/ Share on other sites More sharing options...
BlueSkyIS Posted January 13, 2011 Share Posted January 13, 2011 debug. turn on all error_reporting. echo $output to make sure it's what you expect. echo $target_path to make sure it's what you expect. make sure $target_path is writable, but you'd probably get an error if it's not and you have error_reporting turned on. Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159099 Share on other sites More sharing options...
3raser Posted January 14, 2011 Author Share Posted January 14, 2011 It's correct. There was an error uploading the file, please try again!9 BREAK /mods/9.zip Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159137 Share on other sites More sharing options...
3raser Posted January 14, 2011 Author Share Posted January 14, 2011 Newest code, still doesn't work: <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } else { echo "<a href='start_upload.php'>Upload</a> | <a href='search.php'>Search & Browse</a> | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>"; $description = $_POST['description']; $description = mysql_real_escape_string($description); $ip = $_SERVER['REMOTE_ADDR']; $date = date('m-d-y'); $title = $_POST['title']; $title = mysql_real_escape_string($title); $user = $_SESSION['SESSION']; if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip") { $query = mysql_query("SELECT COUNT(id) FROM mods"); $finish_query = mysql_fetch_assoc($query); $output = $finish_query['COUNT(id)'] + 1; $target_path = "mods/"; $_FILES['file']['name'] = $output.".zip"; $target_path = $target_path . basename($_FILES['file']['name']); if(move_uploaded_file(basename($_FILES['file']['name']), $target_path)) { echo "The mod ". $title . " has been uploaded. Check it out <a href='mods/". $output ."'>HERE.</a>"; mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')"); } else{ echo "There was an error uploading ". $_FILES['file']['name'] ." the file, please try again!"; } } else { echo "You cannot use a .". pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION) ." extension! .zip is currently the only file extension allowed."; } } include("includes/footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159142 Share on other sites More sharing options...
3raser Posted January 14, 2011 Author Share Posted January 14, 2011 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159158 Share on other sites More sharing options...
3raser Posted January 14, 2011 Author Share Posted January 14, 2011 Hello? :/ Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159206 Share on other sites More sharing options...
BlueSkyIS Posted January 14, 2011 Share Posted January 14, 2011 i don't see error_reporting turned on in your script. is it turned on in php.ini? i don't see the code that would cause this output: There was an error uploading the file, please try again!9 BREAK /mods/9.zip Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159215 Share on other sites More sharing options...
3raser Posted January 14, 2011 Author Share Posted January 14, 2011 i don't see error_reporting turned on in your script. is it turned on in php.ini? i don't see the code that would cause this output: There was an error uploading the file, please try again!9 BREAK /mods/9.zip } else{ echo "There was an error uploading ". $_FILES['file']['name'] ." the file, please try again!"; } I get this with errorreporting(E_ALL); Notice: Undefined index: SESSION in /home/a8079066/public_html/upload.php on line 26 As you see, no errors. (Just a small session one, which does no help) Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159221 Share on other sites More sharing options...
3raser Posted January 14, 2011 Author Share Posted January 14, 2011 Hello...? Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159231 Share on other sites More sharing options...
3raser Posted January 14, 2011 Author Share Posted January 14, 2011 Bump Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159542 Share on other sites More sharing options...
BlueSkyIS Posted January 14, 2011 Share Posted January 14, 2011 the undefined index notice tells you that $_SESSION['SESSION'] is undefined. $_SESSION['SESSION'] is not set. don't know if that is responsible for the other issue, but you shouldn't see any notices, errors or warnings if everything is okay. Where is the 9 BREAK /mods/9.zip coming from in this line? There was an error uploading the file, please try again!9 BREAK /mods/9.zip Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159550 Share on other sites More sharing options...
3raser Posted January 14, 2011 Author Share Posted January 14, 2011 the undefined index notice tells you that $_SESSION['SESSION'] is undefined. $_SESSION['SESSION'] is not set. don't know if that is responsible for the other issue, but you shouldn't see any notices, errors or warnings if everything is okay. Where is the 9 BREAK /mods/9.zip coming from in this line? There was an error uploading the file, please try again!9 BREAK /mods/9.zip $_FILES['file']['name'] = $output.".zip"; $target_path = $target_path . basename($_FILES['file']['name']); and echo "There was an error uploading ". $_FILES['file']['name'] ." the file, please try again!"; Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159559 Share on other sites More sharing options...
3raser Posted January 15, 2011 Author Share Posted January 15, 2011 Anyone? I would like to get this working. :/ Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159607 Share on other sites More sharing options...
3raser Posted January 15, 2011 Author Share Posted January 15, 2011 Bump! Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159639 Share on other sites More sharing options...
DavidAM Posted January 15, 2011 Share Posted January 15, 2011 This: if(move_uploaded_file(basename($_FILES['file']['name']), $target_path)) is not correct. You should be moving the temporary file (created by the upload process) to your desired destination. The 'name' element of the FILES array, is the filename from the user's system - well, it was before you changed it a couple of lines above. The uploaded file, the one you need to move is in the 'tmp_name' element of the array -- and do NOT use the basename() function on it. if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159651 Share on other sites More sharing options...
3raser Posted January 15, 2011 Author Share Posted January 15, 2011 This: if(move_uploaded_file(basename($_FILES['file']['name']), $target_path)) is not correct. You should be moving the temporary file (created by the upload process) to your desired destination. The 'name' element of the FILES array, is the filename from the user's system - well, it was before you changed it a couple of lines above. The uploaded file, the one you need to move is in the 'tmp_name' element of the array -- and do NOT use the basename() function on it. if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) Wow....thank you. And why not use basename? Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159659 Share on other sites More sharing options...
DavidAM Posted January 15, 2011 Share Posted January 15, 2011 basename() strips off the path component, leaving only the filename and extension. I don't think the tmp_name will usually have a path component, so it shouldn't really matter - however, if PHP were to put a path component on the tmp_name, it would need to be there for move_uploaded_file() to work. Quote Link to comment https://forums.phpfreaks.com/topic/224360-upload-error/#findComment-1159663 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.