Page 1 of 1

help with upload script and form

Posted: Tue Feb 21, 2006 3:22 pm
by jasondavis
I cant figure this out for nothing I have a form like this...the problem is the result always says No File Selected.

Code: Select all

<form action="contactprocess.php" method="post" multipart/form-data>
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />

<input type="hidden" name="ip" value="70.118.40.221" />
<input type="hidden" name="httpref" value="http://www.projectmyspace.com/" />
<input type="hidden" name="httpagent" value="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; {D83082F7-1067-4A79-8193-4B40EEDCC689}; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" />
<input type="hidden" name="subject" value="featured" />

								  
  <table width="100%" border="0">
    <tr> 
      <td width="29%">Name:</td>
      <td width="37%"><input type="text" name="visitor" value="jason"></td>
    </tr>
    <tr> 
      <td>Myspace Friend ID:</td>
      <td><input type="text" name="friendId" value="29121987"></td>
    </tr>
    <tr> 
      <td> PayPal Email:</td>
      <td><input type="text" name="visitormail" value="fgf@dfd.com"></td>
    </tr>
    <input type="hidden" name="message" value="none" />
    <tr> 
      <td>Image to use</td>
      <td><input type='file' name='file1' ONchange="preview(myimga,file1);" /> 
        <input type='hidden' name='num' value='1'></td>
    </tr>
    <tr> 
      <td>Image Preview</td>
      <td><span class="imgborder"><img alt="preview" border="0" width="150" name="myimga" src="cannotshow.gif" /></span></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td></td>
    </tr>
    <tr> 
      <td colspan="2"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input name="Send" type="submit" value="                       Continue                     "> 
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td></td>
    </tr>
  </table>
</form>


this form submit to a script with this code in it...


Code: Select all

// Start Upload section

if ($imsg<>"") echo $imsg . "<BR>"; 


$visitor = $_POST['visitor'];
	
$uploadDir = 'featured/uploads/';
$time = time();
$today = date("mdy");              
$filePrefix = $_POST['friendId'] . '_' . $visitor . '_' .  $time . '_' . $today . '_';
$num = $_POST['num']; 

for ($x = 1; $x <= $num; $x++) { 
	// Make sure a file has been selected for upload 
	if (is_uploaded_file($_FILES['file'.$x]['tmp_name'])) { 

		$isImg = eregi('.*\.(jpg|jpeg|gif|png)',$_FILES['file'.$x]['name']);
	
		// Get the size of the current file 
		$size = $_FILES['file'.$x]['size']; 

		// Make sure that this file is <= to 100KB 
		if ($size <= 500000 && $isImg) { 
			// get current time to use for filenames
			//$time = time();

			// Move the uploaded file 
			// here we apply the time to the filename but all add the current upload file number
			// this will solve the problem if two or more files are processed in the same second
			// username is kept for easier identification
			// new   wmw 12/17/04
			echo "<br>";
			$new_name = $_FILES['file' . $x]['name'];
			//$new_name = preg_replace(array('/', '\\', '\'', '"'), array("","","",""), $new_name);
			if (move_uploaded_file($_FILES['file'.$x]['tmp_name'],$uploadDir.'/' . $filePrefix . $new_name)) { 
				$uploadCount++;
		

		

				echo "
				<table width='100%' border='0' cellspacing='0' cellpadding='1'>
				<tr bgcolor='F0F0F0'>
				<td>
				<img src='" . $uploadDir.'/' . $filePrefix . $new_name . "' width='175' border='0'>
				</td>
				</tr>
				</table>
				<br>";

				// Store log details -- Will be sent by email
				$upload_exists = 1;
				$upload_log .= "<img src='http://www.projectmyspace.com/signs/$uploadDir/". $filePrefix . $new_name . "'> was uploaded.\nThis file will need to be approved before it will appear.";

				// Change some permissions
				chmod($uploadDir.'/' . $filePrefix . $new_name ,0777);

			} else { 
				// Unable to move file 
				echo "File: ".$uploadDir.'/' . $filePrefix . $new_name . " error moving file.<BR>"; 

			} 

		} else { 
			// File too large 
			echo "File: ".$uploadDir.'/' . $filePrefix . $new_name . "File Too Large.<BR>"; 
		} 
	} else { 
		// No file selected 
		echo "No File Selected.<BR>"; 
	} 
} //End of loop 



// End Upload section

Posted: Tue Feb 21, 2006 3:23 pm
by feyd
you have multipart/form-data but are missing the attribute name

Code: Select all

<form action="contactprocess.php" method="post" enctype="multipart/form-data">

Posted: Tue Feb 21, 2006 3:37 pm
by jasondavis
that was quick ok cool so most of my code is working,
you have multipart/form-data but are missing the attribute name
ok so thats the source of the problem, when you say the attribute is missing im lost there, how could I get this to work?

Posted: Tue Feb 21, 2006 3:39 pm
by feyd
I gave you the new code to use in your html.

Posted: Tue Feb 21, 2006 3:41 pm
by jasondavis
oh I see now thank you very much

Posted: Tue Feb 21, 2006 3:54 pm
by jasondavis
Weird I still end up with

No File Selected.

no matter what, any other ideas?

Posted: Tue Feb 21, 2006 3:58 pm
by feyd
var_export($_FILES)
You may have an error code or the upload failed for various reasons. Your upload directory may not be found or isn't writable either. Make sure you have error_reporting() turned up all the way.