Jump to content

[SOLVED] File not reading


Ninjakreborn

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.