Ok,
I have this file upload php script that inserts the product info fine but when it gets to the file upload portion it only puts out what I want it to when the file does not exist (as in the user did not specify one) or if the file is succesfully uploaded.
The $limage variable is on the included php file and should be echoed according to what happened on the file upload...
So here is the script:
$path = "/www/u/username/htdocs/userp/";
$max_size = 40000;
if (!isset($HTTP_POST_FILES['userfile']))
exit;
$limage = "You did not specify a file to insert. Either delete this product and re-insert with the desired image file or contact us at <a href=\"mailto:support@findyourtoy.com\">support@findyourtoy.com</a> and attatch the image for us to insert manually.<br>Include this Product Id number with your email. <br><strong>Id: " .$productid. "</strong>\n";
include 'insertfin.php';
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tm
p_name'])) {
$limage = "";
if ($HTTP_POST_FILES['userfile']['size']>$max_size) { exit; include 'insertfin.php'; $limage = "The file is too big. Please contact us at <a href=\"mailto:support@findyourtoy.com\">support@findyourtoy.com</a> and attatch the image for us to insert manually.<br>Include this Product Id number with your email. <strong>Id: " .$productid. "</strong>\n"; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { $limage = "File upload failed because file already exists. Either delete this product and re-insert with the image file renamed or contact us at <a href=\"mailto:support@findyourtoy.com\">support@findyourtoy.com</a> and attatch the image for us to insert manually.<br>Include this Product Id number with your email. <br><strong>Id: " .$productid. "</strong>\n"; exit; include 'insertfin.php'; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { $limage = "Because of some unknown problem your image has failed to upload. Please contact us at <a href=\"mailto:support@findyourtoy.com\">support@findyourtoy.com</a> and attatch the image for us to insert manually.<br>Include this Product Id number with your email. <strong>Id: " .$productid. "</strong>\n"; exit; include 'insertfin.php'; } else { $limage = "Upload Sucessful! Your image was a <strong>".$HTTP_POST_FILES['userfile']['type']."</strong> and was titled <strong>".$HTTP_POST_FILES['userfile']['name']."</strong>. The storage taken by this image is <strong>".$HTTP_POST_FILES['userfile']['size']." KB</strong>. This image will appear when users load the product profile.<br>\n"; }
$fname = $HTTP_POST_FILES['userfile']['name'];
$fsize = $HTTP_POST_FILES['userfile']['size'];
$ftype = $HTTP_POST_FILES['userfile']['type'];
$fpath = "/www/u/username/htdocs/userp/" .$fname. "";
$fimage = "http://www.findyourtoy.com/userp/" .$fname. "";
$sqlfp = mysql_query("UPDATE products SET prodimage='$fimage',impath='$fpath' WHERE productid='$productid'");
//echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
//echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
//echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
} else { $limage = "File upload could not be completed because of wrong file type. Please contact us at <a href=\"mailto:support@findyourtoy.com\">support@findyourtoy.com</a> and attatch the image for us to insert manually.<br>\n"; exit; }
include 'insertfin.php';
}}
Ok, I want the "insertfin.php" file to be included no matter how the outcome of the file upload and I want the $limage variable to output based on the outcome but it does not seem to be working on most occasions. What is wrong with my coding??
Thanks
Ryan