june_c21 Posted March 30, 2010 Share Posted March 30, 2010 HI , When i try to upload file , it said "Sorry, there was a problem uploading your file." Can someone let me know what is the problem ? <?php include './includes/header.php'; for ($i=1;$i<11;$i++) { $id = $_GET ['id']; $causes = $_POST ['causes'][$i]; if(empty($causes)) break; $corrective_action = $_POST ['corrective_action'][$i]; $name = $_POST ['name'][$i]; $date = $_POST ['date'][$i]; $completedate = $_POST ['completedate'][$i]; $remarks = $_POST ['remarks'][$i]; $status = $_POST ['status']; $query= "INSERT INTO corrective_action( id, causes, corrective_action, name, date, completedate, remarks ) VALUES ('$id','$causes','$corrective_action','$name','$date','$completedate','$remarks') "; $result = mysql_query($query,$dblink); $query1= "UPDATE event SET status= '$status' where id=$id "; $result1 = mysql_query($query1,$dblink); $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } $file_id = 3 ; $query = "UPDATE corrective_action SET file_name = '$target' WHERE file_id=$file_id"; $result = mysql_query($query,$dblink); $file_id ++ ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/196936-upload-file-problem/ Share on other sites More sharing options...
ocpaul20 Posted March 30, 2010 Share Posted March 30, 2010 I am a simple soul and if I were you, I would put literals into the code and test only the line that you think is failing. If that fails, then it must be a system problem. If that works, then put a variable into the statement and test that. Print out the variable before you put it into the statement to make sure that the file name is correct. Hope that is some help at least. Quote Link to comment https://forums.phpfreaks.com/topic/196936-upload-file-problem/#findComment-1033904 Share on other sites More sharing options...
june_c21 Posted March 30, 2010 Author Share Posted March 30, 2010 when i echo $target it only display upload/ any idea what i miss out in that line $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; Quote Link to comment https://forums.phpfreaks.com/topic/196936-upload-file-problem/#findComment-1033919 Share on other sites More sharing options...
PFMaBiSmAd Posted March 30, 2010 Share Posted March 30, 2010 $_FILES['uploaded']['name'] does not exist due to one of the half-dozen or so possible upload errors and your code has very little error checking logic in it (and some of it is not doing anything such as the size check because the variable $uploaded_size is not being set by your code.) See this other recent thread for some upload error checking logic to get you started - http://www.phpfreaks.com/forums/index.php/topic,292945.0.html Quote Link to comment https://forums.phpfreaks.com/topic/196936-upload-file-problem/#findComment-1033921 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.