Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.