Help me with jpg upload through HTTP Post with PHP!

cyberock

Member
Apr 19, 2002
95
0
0
I'm trying to upload a jpg image through a form. I am very new to the linux anvironment and php. I was a recent coldfusion developer and always worked on windows so I have a lot to learn. I ran and test my code locally on my windows IIS. I moved it up to a linux server and now it doesn't work. I don't even get an error. It just doesn't upload anything. Here's the important parts of my code...

form page:
<form method="post" action="add_image.php" enctype="multipart/form-data">
Thumb Nail Image:
<input type="file" name="ThumbImg" size="30">
<input type="submit" name="Submit" value="Submit">
</form>

Upload Page: ( I don't know the direct path on the server so that's the reasoning for the "../.../")

$images_query = "SELECT Max(models_id) FROM models_main";
$images_result = mysql_query($images_query, $db_connection)or die(mysql_error());
$image_id = mysql_result($images_result, 0, 0);


$_FILES['ThumbImg']['name'];
if(file_exists($_FILES['ThumbImg']['name'])) {
rename('' . $_FILES['ThumbImg']['tmp_name'],'../../images/thumb/' . $image_id .'.jpg');


Thanks in adavance for the help!
}
 

Entity

Lifer
Oct 11, 1999
10,090
0
0
Do you have write access in all the proper directories?

Also, your syntax for rename seems incorrect, and I'm not sure why you are renaming the image rather than copying it. Generally tmp_name is something like /tmp/randomimagename, and you'd want to do something like this:

$newfile = $dirname . "/" . $_FILES['photo']['name'];

if(!copy($_FILES['photo']['tmp_name'], $newfile))
{
echo "Could not copy files.";
exit;
}

If you continue having problems, check the _FILES array to make sure that it is properly being uploaded, etc.

Rob
 

cyberock

Member
Apr 19, 2002
95
0
0
Thanks for the help! I finally got it to work by doing this but I feel I added in an extra step...

$newfile = $_FILES['ThumbImg']['name'];
copy($_FILES['ThumbImg']['tmp_name'], $newfile);
rename( $_FILES['ThumbImg']['name'],'../../images/thumb/' . $image_id .'.jpg');
 

Entity

Lifer
Oct 11, 1999
10,090
0
0
Originally posted by: cyberock
Thanks for the help! I finally got it to work by doing this but I feel I added in an extra step...

$newfile = $_FILES['ThumbImg']['name'];
copy($_FILES['ThumbImg']['tmp_name'], $newfile);
rename( $_FILES['ThumbImg']['name'],'../../images/thumb/' . $image_id .'.jpg');

First of all, $_FILES['ThumbImg']['name'] should already have a jpg extension, if that is the file someone uploaded. It's just the name of the file that was uploaded. Either way, though, it doesn't look like you want the final jpg file to have that name, but instead a pre-assigned name (based on $image_id). So why not do this? Since I can't see all your code, I don't know where you get the $image_id variable from, but this should still work.

$newfile = "../../images/thumb/" . $image_id . ".jpg";
copy($_FILES['ThumbImg']['tmp_name'], $newfile);

Rob
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |