View Full Version : FILE Upload problem

03-02-2007, 05:50 AM
I had a working upload script... And I somehow goofed it up...

In the addproduct function you will find

if( !empty( $_POST['file_front'] ) ) { upload_image('file_front', $file_name . "_front"); }
if( !empty( $_POST['file_back'] ) ) { upload_image('file_back', $file_name . "_back"); }
if( !empty( $_POST['file_detail'] ) ) { upload_image('file_detail', $file_name . "_detail"); }

And the upload_image function

function upload_image($file_to_upload, $new_name){

define(MAX_SIZE, 25000);
define(TARGET, 'coacter/static/products');
//Create New File Name And Find out File Type
$the_file = TARGET . "/" . $new_name;
$uploaded_type = $_FILES[$file_to_upload]['type'];

$file_err = false;

if ($uploaded_size > MAX_SIZE){$file_err = true;$exception = "File size is too large. <br />";}

//Only Allow Images//
if ( !strstr( $uploaded_type, "image") ){ $file_err = true; $exception .= "This is not an image. <br />"; }

//See if there was an error
if ($file_err==true){
print $exception . "< br /> Sorry, your file could not be uploaded.<br />Please Go Back!";

$file_split = explode('.', $_FILES[$file_to_upload]['name']);
$extension = "." . $file_split[count($file_split)-1];

if(move_uploaded_file($_FILES[$file_to_upload]['tmp_name'], $the_file . $extension)){
print "Your file was uploaded!";
print "Sorry, there was a problem uploading your file. Please Go Back!";

I tried little print statements throughout to find my problem but... I cant figure out why it isn't working. Any thoughts? I have been starting at this for HOURS..:confused:

03-02-2007, 05:55 AM
Forgot the Error.... It tells me the file is not an image... The script was working until I put it into a function.... Not sure if that is it.. But..

03-02-2007, 08:40 PM
Make sure you set the enctype, and make sure the file input is named file_front or etc., and if it doesn't work post your form code(HTML).