Page 1 of 1

uploading error

Posted: Fri Oct 07, 2011 9:41 am
by digrev01
hi eveybody im very confused because this code doesnt work i dont know whats is wr0ng... intresting thing is

it works just one equal sign but should be double




<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<input type="file" name="dosya" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>



<?php
$Kaynak=$_FILES["dosya"]["tmp_name"];
$Dsize=$_FILES["dosya"]["size"];
$ad=$_FILES["dosya"]["name"];
$tur=$_FILES["dosya"]["type"];
$hedef="./images";
if($tur=="image/png" || $tur=="image/gif" || $tur=="image/jpg")
{
$sonuc=move_uploaded_file($Kaynak,$hedef.'/'.$ad);
if($sonuc)
echo "ok";
}
?>

Re: uploading error

Posted: Fri Oct 07, 2011 9:49 am
by social_experiment

Code: Select all

<?php
$Kaynak=$_FILES["dosya"]["tmp_name"];
$Dsize=$_FILES["dosya"]["size"];
$ad=$_FILES["dosya"]["name"];
$tur=$_FILES["dosya"]["type"];
$hedef="./images";
if($tur=="image/png" || $tur=="image/gif" || $tur=="image/jpg")
{
$sonuc=move_uploaded_file($Kaynak,$hedef.'/'.$ad);
if($sonuc) echo "ok";
// add this to your code
else {
 echo $_FILES['doysa']['error'];
}
// --
}
?>
Add the bit of code above to your script, once the upload fails, an error code will be returned and you will have a place to start looking. You should also add a hidden field to the form named MAX_FILE_SIZE with the maximum allowed filesize (in kilobytes) that the user can upload. It can be bypassed but it's good practise to have it in place.

Re: uploading error

Posted: Fri Oct 07, 2011 12:31 pm
by digrev01
hi again if i change the code (this way like below) it works great but i cant understand why...could you explain please what was wrong
$hedef="./images";
if($tur == "image/jpeg" || $tur == "image/png" || $tur == "image/pjpeg" ||$tur == "image/bmp" )
{

move_uploaded_file($kaynak,$hedef.'/'.$ad);

}

Re: uploading error

Posted: Sat Oct 08, 2011 2:52 am
by social_experiment
Probably because of the extension .jpg. I've im not mistaken, the correct MIME type is image/jpeg or image/pjpeg as you have it now.

Re: uploading error

Posted: Sat Oct 08, 2011 10:59 am
by digrev01
Yes my friend you are right because of MIME type thank yoıu for your help :))