Jump to content

upload image help


pluginbaby

Recommended Posts

[code]<?php
if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg")
&& ($_FILES["file"]["size"] < 64000))
  {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else {
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";   

if (file_exists("upload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
}
else {
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else {
echo "Invalid file";
}

?>[/code]

here is my test code to upload a file, later it needs more working out :)

But I got basic, and when I tested, I succesfully uploaded a .gif file (whoohoow), but when I tried a .jpg or a .jpeg, it displayed "Invalid file". How can this be helped (better: can this be helped? :) )
Link to comment
https://forums.phpfreaks.com/topic/28432-upload-image-help/
Share on other sites

You can check file type on the top of your script.

<?php
[color=red]
print_r($_FILES["file"]["type"]) ;
exit;
[/color]

if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg")
&& ($_FILES["file"]["size"] < 64000))
 {
...............
.........
...

You can see file type such as: "image/pjpeg"
Then remove
[color=red]
print_r($_FILES["file"]["type"]) ;
exit;
[/color]
and put type of file that you see in your script ('if' statement).

Hope it helps


Link to comment
https://forums.phpfreaks.com/topic/28432-upload-image-help/#findComment-130149
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.