Jump to content

Recommended Posts

Hi. I've got the following code to upload an image file, and when you upload to a single location (without the 'thumb' upload it works fine, but as I want the image to be uploaded twice, it won't work. it fails at the point of checking whether the thumbs directory is writable, and it definitely is but it fails!

 

Can anyone help at all?? THe code is below! THanks!

 

  // Configuration - Your Options
      $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); 
      $max_filesize = 524288; 
      $upload_path = 'user_files/uploaded/images/uploaded/'; 
      $upload_thumb_path = $upload_path.'thumbs/'; 

   $filename = $_FILES['userfile']['name']; 
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');

   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');

   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');

   if(!is_writable($uploa_thumbd_path))
      die('You cannot upload to the specified directory thumb, please CHMOD it to 777.');

   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed .
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_thumb_path . $filename))
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed .

Link to comment
https://forums.phpfreaks.com/topic/72632-solved-image-upload-not-working/
Share on other sites

you have a spelling error:

 

  $upload_thumb_path = $upload_path.'thumbs/'; 
  if(!is_writable($uploa_thumbd_path))

//change to:
  $upload_thumb_path = $upload_path.'thumbs/'; 
  if(!is_writable($upload_thumb_path))

 

good luck

Right, I've corrected the spelling and now it isn't bringing up an error for the path not being writable, however, the main image is uploading but the 'thumb' one isn't its just returning the error. I can't see why.

  // Configuration - Your Options
      $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); 
      $max_filesize = 524288; 
      $upload_path = 'user_files/uploaded/images/uploaded/'; 
      $upload_thumb_path = $upload_path.'thumbs/'; 

   $filename = $_FILES['userfile']['name']; 
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');

   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');

   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');

   if(!is_writable($upload_thumb_path))
      die('You cannot upload to the specified directory thumb, please CHMOD it to 777.');

   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed .
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_thumb_path . $filename))
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed .

 

 

I've got it working now by using the following code! Thanks for everyone's help!

  // Configuration - Your Options
      $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); 
      $max_filesize = 524288; 
      $upload_path = 'user_files/uploaded/images/uploaded/'; 
      $upload_thumb_path = $upload_path.'thumbs/'; 

   $filename = $_FILES['userfile']['name']; 
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');

   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');

   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');

   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) {
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
	 if(copy($upload_path.$filename, $upload_thumb_path.$filename))
	 echo 'Thumbnail created successfully'.$filename;
	else
		echo 'Thumbnail hit a wall!';
	}
      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed .

 

 

Hi, I had already marked it as solved, guess you viewed it jus b4 I hit the solved button, as the email telling me the topic had been replied to (basically when you posted on it) had "SOLVED" in the subject line!

 

Thanks for your help, I can go to bed now and not worry about any more PHP til the morning (I'm in the UK, its 00:34 here!!)

 

Nite all!

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.