...

View Full Version : FILE Upload problem



jayemvee
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!";
}else{

$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!";
}else{
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:

jayemvee
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..

Inigoesdr
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).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum