Jacobian Posted August 27, 2009 Share Posted August 27, 2009 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 More sharing options...
gaza165 Posted August 27, 2009 Share Posted August 27, 2009 turn on error reporting, put the code below at the top of the page after <?php error_reporting(E_ALL); do you get any errors on upload?? Link to comment https://forums.phpfreaks.com/topic/172116-image-uploader-problems/#findComment-907505 Share on other sites More sharing options...
Jacobian Posted August 27, 2009 Author Share Posted August 27, 2009 hey gaza165, thanks for replying.. i got the following error: NOTICE: Undefined Variable arror in ... on line 227 Line 227 just has: errors($error); (calling a function to display any errors if they exist) Link to comment https://forums.phpfreaks.com/topic/172116-image-uploader-problems/#findComment-907979 Share on other sites More sharing options...
waynew Posted August 27, 2009 Share Posted August 27, 2009 Are you sure that the script causing the errors is not an older version of something that you were working on? Because arror seems like a typo of the word error. Link to comment https://forums.phpfreaks.com/topic/172116-image-uploader-problems/#findComment-907982 Share on other sites More sharing options...
Jacobian Posted August 28, 2009 Author Share Posted August 28, 2009 haha oops... yeah that was a typo.. my bad NOTICE: Undefined Variable error in ... on line 227 the error function works though... (displays errors when they occur) the problem im having is with the upload part of the script. Link to comment https://forums.phpfreaks.com/topic/172116-image-uploader-problems/#findComment-907990 Share on other sites More sharing options...
waynew Posted August 28, 2009 Share Posted August 28, 2009 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" Link to comment https://forums.phpfreaks.com/topic/172116-image-uploader-problems/#findComment-907996 Share on other sites More sharing options...
Jacobian Posted August 28, 2009 Author Share Posted August 28, 2009 ok sweet, yeah thats what was happening.. got rid of that error.. but the images are still not being uploaded. Link to comment https://forums.phpfreaks.com/topic/172116-image-uploader-problems/#findComment-908014 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.