Ninjakreborn Posted February 22, 2007 Share Posted February 22, 2007 I am having a problem, I have a file upload <p>File 1 Upload Area</p> <label for="image1">Image Version</label> <input name="image1" id="image1" type="file" /><br /> <label for="pdf1">PDF Version</label> <input name="pdf1" id="pdf1" type="file" /><br /> <label for="comments1">Comments:</label> <input name="comments1" id="comments1" type="text" maxlength="220" /> <br /> That is the upload form. Now I have the script. <?php echo "UPLOAD STATUS"; // Just echo the start of information # Prepare all variables // id $id = $_POST['id']; // get id $docroot = $_SERVER['DOCUMENT_ROOT']; // get docroot $target = $docroot . "/clients/proofs/"; // create target url with docroot and path // first set $image1 = $_FILES['image1']; $pdf1 = $_FILES['pdf1']; if (isset($_POST['comments2'])) { $comments1 = $_POST['comments1']; }else { $comments1 = FALSE; } // second set $image2 = $_FILES['image2']; $pdf2 = $_FILES['pdf2']; if (isset($_POST['comments2'])) { $comments2 = $_POST['comments2']; }else { $comments2 = FALSE; } // third set $image3 = $_FILES['image3']; $pdf3 = $_FILES['pdf3']; if (isset($_POST['comments3'])) { $comments3 = $_POST['comments3']; }else { $comments3 = FALSE; } // fourth set $image4 = $_FILES['image4']; $pdf4 = $_FILES['pdf4']; if (isset($_POST['comments4'])) { $comments4 = $_POST['comments4']; }else { $comments4 = FALSE; } // fifth set $image5 = $_FILES['image5']; $pdf5 = $_FILES['pdf5']; if (isset($_POST['comments5'])) { $comments5 = $_POST['comments5']; }else { $comments5 = FALSE; } // sixth set $image6 = $_FILES['image6']; $pdf6 = $_FILES['pdf6']; if (isset($_POST['comments6'])) { $comments6 = $_POST['comments6']; }else { $comments6 = FALSE; } // seventh set $image7 = $_FILES['image7']; $pdf7 = $_FILES['pdf7']; if (isset($_POST['comments7'])) { $comments7 = $_POST['comments7']; }else { $comments7 = FALSE; } // eight set $image8 = $_FILES['image8']; $pdf8 = $_FILES['pdf8']; if (isset($_POST['comments8'])) { $comments8 = $_POST['comments8']; }else { $comments8 = FALSE; } // ninth set $image9 = $_FILES['image9']; $pdf9 = $_FILES['pdf9']; if (isset($_POST['comments9'])) { $comments9 = $_POST['comments9']; }else { $comments9 = FALSE; } // tenth set $image10 = $_FILES['image10']; $pdf10 = $_FILES['pdf10']; if (isset($_POST['comments10'])) { $comments10 = $_POST['comments10']; }else { $comments10 = FALSE; } // Below we need to go through each file. It's going to be the same process with each file // So I am going to make an attempt at doing this with an array, to make it faster. // As well as make it carry better performance. // set 1 echo "<hr />"; echo "<strong>Set 1 Status</strong>"; echo "<br />"; if (!empty($image1['name']) && !empty($pdf1['name'])) { // check if both images where uploaded // get all names prepared for uploading // get image names $image1tmp = $image1['tmp_name']; $image1name = $id . "_" . $image1['name']; $image1target = $target . $image1name; // get pdf names $pdf1tmp = $pdf1['tmp_name']; $pdf1name = $id . "_" . $pdf1['name']; $pdf1target = $target . $pdf1name; echo "image temp"; echo "<br />"; echo $image1tmp; echo "<br />"; echo "pdf name"; echo "<br />"; echo $pdf1tmp; echo "<br />"; exit; if (is_uploaded_file($image1tmp) && is_uploaded_file($pdf1tmp)) { if (move_uploaded_file($image1tmp, $image1target) && move_uploaded_file($pdf1tmp, $pdf1target)) { echo "Files were uploaded successfully.<br />"; $insert = "INSERT INTO proofs(userid, imagename, pdfname, comments) VALUES('$id', '$image1name', '$pdf1name', '$comments1')"; if (mysql_query($insert)) { echo "It was also uploaded into the database successfully.<br />"; }else { echo "Problem's inserting it into database though.<br />"; } }else { echo "There was a problem uploading one of these files.<br />"; } }else { echo "The files did not make it to temporary upload.<br />"; } }else { echo "<span style=\"color:red\">You did not upload a file for this set, or you only uploaded one.<br /> Both are required. You must have both a pdf version as well as<br/ > an image version for it to work properly.</span><br />"; } // set 2 echo "<hr />"; echo "<strong>Set 2 Status</strong>"; ?> You see the debugging code in there, it is not noticing the image tmp name. The tmp name of the pdf file is being recorded, however for the first file it is not noticing. I double/triple checked my variables, it appears as if it's unsetting my variable out of nowhere? Any advice? EDIT I know for a fact it is making it to atleast <?php if (!empty($image1['name']) && !empty($pdf1['name'])) { ?> That line of code. This is the problem, it is making it past that (or the debugging code would not even run. This is a rather strange problem I have never encountered before. Quote Link to comment https://forums.phpfreaks.com/topic/39654-solved-file-not-reading/ Share on other sites More sharing options...
Ninjakreborn Posted February 22, 2007 Author Share Posted February 22, 2007 The problem is when I let the code go, it comes up and when it tests if the 2 were uploaded with is_uploaded_file, it always gives the else statement instead. Can anyone see what is going on with this script? Quote Link to comment https://forums.phpfreaks.com/topic/39654-solved-file-not-reading/#findComment-191436 Share on other sites More sharing options...
Ninjakreborn Posted February 22, 2007 Author Share Posted February 22, 2007 More information. It is like on acid. At one minute it's reading them both but still not using the script properly. Then the next time it reads one but not the other, or vice versa. There is something going on here, I am not aware of. I have never encountered this type of "erratic" behavior with a script before. Quote Link to comment https://forums.phpfreaks.com/topic/39654-solved-file-not-reading/#findComment-191443 Share on other sites More sharing options...
Ninjakreborn Posted February 22, 2007 Author Share Posted February 22, 2007 I try echoing out an array fo the file's, however it's passing the name, but the other stuff is coming up blank. The error array is returning 1, the name is coming through and "all" other variables in the array are coming up empty. Quote Link to comment https://forums.phpfreaks.com/topic/39654-solved-file-not-reading/#findComment-191491 Share on other sites More sharing options...
Ninjakreborn Posted February 22, 2007 Author Share Posted February 22, 2007 I found the problem, it was the ini file. I had just 8 so it was too small, then I tried 8mb, didn't work 8M worked, it was 1 that was returned in the error, which meant it was the ini file was not allowing it to upload. I fixed the issue and it's uploading alright. Quote Link to comment https://forums.phpfreaks.com/topic/39654-solved-file-not-reading/#findComment-191499 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.