/    Sign up×
Community /Pin to ProfileBookmark

Uploading and Inserted Pictures into database

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.”);
}
?>[/code]

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?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tirnaAug 28.2010 — I would do some Basic Debugging 101 (post #1) to find which of the if() conditions is causing the message to be ouputted and then fix the code accordingly.
Copy linkTweet thisAlerts:
@impaKtauthorAug 29.2010 — Well, mystery solved: it had to do with wamp's image size restrictions. It has been fixed. Thanks a lot for the help guys, once again.
×

Success!

Help @impaKt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...