Jump to content

PHP Image upload help!


masonite85

Recommended Posts

This is code I am working on. It is suppose to take a file and check then transfer it to the server in a directory called uploads. It works as far as checking the valid image types and sizes but when it checks to see if the image got to the server it echos the error message that the image was not recieved. I didn't see any problems in the code.

 

<?php
$target = "uploads/";
$target = $target . basename($_FILES['uploaded']['name']);
$ok=1;

if($uplaoded_size < 150000)
{
if($uploaded_type == "image/png")
{
	$ok =1;
}
elseif($uploaded_type == "image/gif")
{
	$ok =1;
}
elseif($uploaded_type == "image/jpeg")
{
	$ok =1;
}
}
else
{
$ok =0;
}

// check if ok is 0. File not ready for uploading
if($ok ==0)
{
echo "Upload failed. Please make sure your file is of type JPEG, PNG or GIF and is smaller than 150.0 KB!";
}
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
	echo "The File was Uploaded: ". basename($_FILES['uploadedfile']['name']). "has been uploaded";	
}
else 
{
	echo "File failed to upload please try again or contact us.";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/48567-php-image-upload-help/
Share on other sites

i'll assume that this is a copy and paste job of your actual script, in which case:

a) check your spelling: if($uplaoded_size < 150000)

b) you're using a handful of vars that seem to come out of nowhere, such as $uploaded_type, $uploaded_size. consider putting this near the top:

<?php
$uploaded_type = $_FILES['uploaded']['type'];
$uploaded_size = $_FILES['uploaded']['size'];
?>

c) check that the directory you're moving the files to ($target) is writable

 

if all of that doesnt work, can you post your HTML's <form> line too as well as the 'exact' error you're getting?

 

Link to comment
https://forums.phpfreaks.com/topic/48567-php-image-upload-help/#findComment-237950
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.