I have a file type input and i want to upload an image. i re-wrote the code like 5times thinking i did a mistake but so far i can't see it. Because it is not working. html code
<form method="post" enctype="multipart/form-data">
<input type="file" name="primaryimg" id="primaryimg"></br>
<input type="submit" value="Sell!" name="uploaditem" />
</form>
And this is my php code
if(isset($_POST['uploaditem'])){
$filebasename = basename($_FILES['primaryimg']['name']);
$ext = strtolower(substr($filebasename, strrpos($filebasename, '.') + 1));
if (($ext == "jpg" || $ext == "gif" || $ext == "png" || $ext == "jpeg") && ($_FILES['primaryimg']['type'] == "image/jpg" || $_FILES['primaryimg']['type'] == "image/gif" || $_FILES['primaryimg']['type'] == "image/png" || $_FILES['primaryimg']['type'] == "image/jpeg")){
$desired_dir="img/products/sellers/$user/$itemname/";
$file_name=$_files['primaryimg']['name'];
if (file_exists($desired_dir . $file_name)){
$errormsg="Filename already exists.";
}else{
move_uploaded_file($_FILES['primaryimg']['tmp_name'], $desired_dir . $file_name);
$errormsg = $file_name . "successfully uploaded.";
}
}else{
$errormsg = "Error! File is not a valid jpg, gif, png or jpeg";
}
}
So i tried echo'ing the $filebasename
where the basename($_FILES)
is located to see what value its getting. Apparently its empty. I did a $lol=$_POST['primaryimg'];
and echo'd $lol
and it did show the item name. so for some reason the $files
stays empty and the move_upload_file
does not work either.
ones putting the error report on i see the following error
Notice: Undefined index: primaryimg in D:\Dropbox\UoC\phphosting\buyathing\sellanitem.php on line 21
After the error shown below that the image is not a jpg/jpeg...it should print the filebasename and as u can see it is EMPTY.
i went to php.ini to see if file_upload
was on and it is. the image i tried uploading was 550k but my max filesize was 2M so that isnt the problem either.
I have been googling for 5hours but no luck. So if someone out there can help me before i lose my mind would be great :')
Thanks in advance.