Re: Image upload form

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





Richard Davey wrote:
Hello Jack,

Wednesday, June 15, 2005, 5:38:11 PM, you wrote:

JJ> newfile returns: 0fdae2e9e6aa43f067a9dd780a5a36a6.jpg
JJ> image_file returns:
JJ> images/jpg/test/0fdae2e9e6aa43f067a9dd780a5a36a6.jpg

JJ> images/jpg/test is set to 777 but I still get (Could not move file to
JJ> destination).  What am I missing? Thanks!

This directory needs to be absolute - i.e. the COMPLETE path:

/usr/home/jack/images/jpg/test



Thanks, Richard,

Still no soap: I changed

      $uploaddir = "/home/jack/public_html/amyportnoy/images/jpg/test";

and
      $image_file = $uploaddir . '/' . $newfile;

Now $image_file returns the valid path of:

/home/jack/public_html/amyportnoy/images/jpg/test/09992d5379dd0a0cf376aab82241a66d.jpg

but it still does not copy the file to that location. However the error has changed:

 if (is_uploaded_file($newfile)) {

	 if(!move_uploaded_file($newfile,$image_file)) {
	
	 echo 'Could not move file to destination';
	 exit;
 }

 else {
	 echo 'image file <?php echo $newfile ?> uploaded.';
      }

 }

 else {
	echo 'Problem with ' . $newfile;
      }

  }
And I'm getting an error message of Problem with 6a26590fb45fd86e58954ba91d5580a4.jpg

So i guess it's not uploading for some reason?

Here's the whole thing I have so far once again, with several mods:



<?php

error_reporting(E_ALL);

      $uploaddir = "/home/jack/public_html/amyportnoy/images/jpg/test";

      print_r($_FILES);


      if ($_FILES['userfile']['error'] > 0) {
	
	echo 'Problem: ';
	
	switch ($_FILES['userfile']['error']) {
	      case 1:
echo 'File exceeds maximum upload size limit (upload_max_filesize).';
		 break;
	      case 2:
	         echo 'File exceeds maximum size limit (max_file_size).';
		 break;
	      case 3:
	         echo 'File was only partially uploaded.';
		 break;
	      case 4:
	         echo 'No file was uploaded.';
		 break;

      }//end switch

      }//end if error >0

      $local_file = $_FILES['userfile']['tmp_name'];

if (sizeof($local_file))
  {

//try to get image size; this returns false if this is not an actual image file.
      $image_test = getimagesize($local_file);

	if ($image_test !== false) {
	   $mime_type = $_FILES['userfile']['type'];
	   switch($mime_type) {
	       case "image/jpeg":
		   $pext = 'jpg';
		   break;
	       case "image/tiff":
		   $pext = 'tif';
		   break;
	       default:
echo "The file you are trying to upload is an image, but it is not a tif or jpeg and therefore unacceptable.";
	   }
} else {
   echo "The file you are trying to upload is not a valid image file";
}

 $newfile = md5(date("l-F-j-Y i:s")).'.'.$pext;

 $image_file = $uploaddir . '/' . $newfile;

// print_r($newfile);
 print_r($image_file);
	

 if (is_uploaded_file($newfile)) {

	 if(!move_uploaded_file($newfile,$image_file)) {
	
	 echo 'Could not move file to destination';
	 exit;
 }

 else {
	 echo 'image file ' . $newfile . 'uploaded.';
      }

 }

 else {
	echo 'Problem with ' . $newfile;
      }

  }

  ?>

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="300000" />
    <!-- Name of input element determines name in $_FILES array -->
    Cartoon: <input name="userfile" type="file" />
    <input type="submit" value="Upload File" />
</form>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux