I’m trying to get this website area to upload photos (thumbnail and full sized ones) and inserting them both into two different folders and into the database. This is the PHP code:
[code]
<?php
if ($_POST[cat] >0) {
$target1 = “gallery/thumbnails/”; //uploaded1
$target2 = “gallery/full/”; //uploaded2
$target1 = $target1 . basename( $_FILES[‘uploaded1’][‘name’]) ;
$target2 = $target2 . basename( $_FILES[‘uploaded2’][‘name’]) ;
$ok=1;
// Size Condition
if ($uploaded1_size > 1000000 || $uploaded2_size > 2000000) {
echo “One or more of your files is too large.<br>”;
$ok=0;
}
//limit file type condition
if ($uploaded1_type == “text/php” || $uploaded2_type ==”text/php”) {
echo “No PHP files<br>”;
$ok=0;
}
if (($_FILES[“uploaded1”][“type”] == “image/gif”) || ($_FILES[“uploaded1”][“type”] == “image/jpeg”) || ($_FILES[“uploaded1”][“type”] == “image/jpg”) ||
($_FILES[“uploaded2”][“type”] == “image/gif”) || ($_FILES[“uploaded2”][“type”] == “image/jpeg”) || ($_FILES[“uploaded2”][“type”] == “image/jpg”)) {
$ok=1;
} else {
echo “You may only upload JPG files.<br>”;
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0) {
Echo “Sorry, your files were not uploaded”;
}
//If everything is ok we try to upload them
else {
if(move_uploaded_file($_FILES[‘uploaded1’][‘tmp_name’], $target1) && move_uploaded_file($_FILES[‘uploaded2’][‘tmp_name’], $target2)) {
mysql_query(sprintf(“INSERT into photos set
thumbnail = ‘%s’,
image = ‘%s’,
created_at = NOW(),
category_id = ‘%s’
“,
$THUMB_ROOT.$_FILES[‘uploaded1’][‘name’], $IMG_ROOT.$_FILES[‘uploaded2’][‘name’], $_POST[cat])
);
echo “The files have been uploaded”;
} else {
[COLOR=”Red”]echo “Sorry, there was a problem uploading your files.”; [/COLOR]
}
}
} else {
echo(“Please select a gallery.”);
}
?>
For some reason, when I try uploading the following pictures: img3_full.jpg and img3_thumb.jpg , it all goes smooth. However, if I try uploading anything else, I get the “Sorry, there was a problem uploading your files” error.
Can anyone figure out why?