Jump to content

Problem Uploading Files


mousmoulis

Recommended Posts

I have made a page through which I upload images to the webserver. Jpeg, gif, png are only accepted. 90% of them are uploaded successfully. But there is a problem with the other 10%. What is happening is that for some reason while in the 90% of the images my page can recognize the size and the type of the image in the other 10% it can't. When I echo the $_FILES['image']['type'], $_FILES['image']['size'] I get nothing and zero respectively. So when I check whether the file is jpeg, png or gif I get the message that the file is not in the right format. But even if I comment out the checking about the file size or type although it looks as if the file was uploaded the file isnot present in the server. It is as if the images aren't thought to be valid files although in my PC they are recognised as e.g. png file with size = 121kb. I have even tried to convert the images to different format or size but the result remains the same. Does anybody knows why some images are recognised and other are not?
Link to comment
Share on other sites

My files are stored locally and using my browser i want to upload images to the webserver.


the code is as follows
but I don't think it has to do with the code
The echos are in Greek and are only messages appearing to the user to know if he has completed his task successfully or not.

[table][tr][td]if ($_FILES['appScreenshot']['name'])

{

$uploaddir = "../images/screenshots/";

$allowed = array('image/gif','image/jpeg','image/png');

$verified_ext = false;



$extension = pathinfo($_FILES['appScreenshot']['name']);

$extension = $extension['extension'];







echo $_FILES['appScreenshot']['size'];


if(in_array($_FILES['appScreenshot']['type'], $allowed))

{

$verified_ext = true;

}

else

{

echo "Η επέκταση του αρχείου της εικόνας δεν είναι έγκυρη. Πρέπει να είναι jpg, gif, png, jpeg";

exit();

}



if($appScreenshot!="")

{

if(is_dir($uploaddir))

{

if(!unlink($uploaddir.$appScreenshot))

{

echo "Δεν είναι δυνατή η διαγραφή της υφιστάμενης εικόνας. Ξαναπροσπαθήστε.";

exit();

}

}

else

{

echo "Η εικόνα δεν είναι καταχωρισμένη σε έγκυρη διαδρομή στο server";

exit();

}

}





$screenshot = $appID.".".$extension;

$final_upload_file = $uploaddir.$screenshot;





if($verified_ext == true)

{

if($_FILES['appScreenshot']['size'] > $max_size)

{

echo "Το μέγεθος της εικόνας είναι πολύ μεγάλο. Εισάγετε εικόνα με μικρότερο μέγεθος.";

exit();

}



if($_FILES['appScreenshot']['size'] == 0)

{

echo "Η εικόνα έχει μηδενικό μέγεθος. Εισάγετε εικόνα με μεγαλύτερο μέγεθος.";

exit();

}



if(is_uploaded_file($_FILES['appScreenshot']['tmp_name']))

{

if(is_dir($uploaddir))

{

if(!file_exists($final_upload_file))

{

if(!move_uploaded_file($_FILES['appScreenshot']['tmp_name'],$final_upload_file))

{

echo "Δεν ήταν δυνατή η αποστολή του αρχείου εικόνας στο sever";

exit();

}



}

else

{

echo "Υπάρχει ήδη αρχείο καταχωρισμένο για την τρέχουσα εφαρμογή";

exit();

}

}

else

{

echo "Η διαδρομή αποθήκευσης της εικόνας δεν είναι έγκυρη";

exit();

}

}
[/table]
Link to comment
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.