Jump to content

Image Uploader Problems


Jacobian

Recommended Posts

Hey guys, i have a registration form which gets users to input their name, email address and also lets them upload a sample image of their photographic works (for a photography site)

 

however what im having troubles with is the image uploader..

 

i have the form information being entered into a database as well as being emailed to both us and the user with the necessary info which is all working fine, but the images are not actually being uploaded to the server.. the folder (uploads) stays empty...

which i believe has something to do with the below piece of code.. (the uploader part of the script)

 

i can also provide the full source code if that is not where the error is...

 

thanks in advance for any help.

 

Cheers,

Jacobian

 

function GetUploadedFileInfo() {
   $file_info[] = basename($_FILES['uploaded_file']['name']);
   $file_info[] = substr($file_info[0], strrpos($file_info[0], '.') + 1);
   $file_info[] = $_FILES["uploaded_file"]["size"]/1024;
   return $file_info;
}
function Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size) {
   if($size_of_uploaded_file>$max_allowed_file_size ) {
   $error[]
   = 'Size of upload must be below ' . $max_allowed_file_size . ' KB.';
      return true;
   }
   // used for sending email later on
    include_once('../PEAR/PEAR/Mail.php');
   include_once('../PEAR/PEAR/Mail/mime.php');

$max_allowed_file_size = "5120"; // this is size in KB 
list($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file) = GetUploadedFileInfo();
if(!Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size)) {
   exit();
}
LoadUploadedFile($name_of_uploaded_file);
$path_of_uploaded_file = "uploads/" . $name_of_uploaded_file;



$allowed_extension = array("jpg", "jpeg", "tif", "tiff");
for($i=0; $i<sizeof($allowed_extension); $i++) { 
   $allowed_extension[$i] = strtoupper($allowed_extension[$i]); 
}
$type_of_uploaded_file = strtoupper($type_of_uploaded_file);
if(!(in_array(strtoupper($type_of_uploaded_file),$allowed_extension))) {
$error[]
   = 'Uploaded file must be of type jpg, jpeg, tif, tiff, your file was a ' . $type_of_uploaded_file;
   return true;
}
function LoadUploadedFile($name_of_uploaded_file) {
   move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], "uploads/" . $name_of_uploaded_file);
   return true;
}

Link to comment
https://forums.phpfreaks.com/topic/172116-image-uploader-problems/
Share on other sites

That means that the variable $error hasn't been set before it was given to your error function. Probably a case of you setting $error inside { and } parenthesis.

 

if($something){

  $error = "etc";

}

 

Echoing $error outside of those { & } parenthesis will cause a PHP warning as $error only technically exists inside the scope of that if statement. So, set it outside aswell. Like so:

 

$error = NULL;

if($something){

  $error = "etc";

}

 

If the the IF statement was proved through, the $error variable that was set outside of the IF statement will now be assigned the value "etc"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.