Jump to content

Uploading Picture Problem


krash11554

Recommended Posts

I have code that checks if a file is selected do this. But my problem is it is running that code even though i dont have a selected file in a input box. heres the code.

if(isset($_FILES['editcar_fileupload']) && empty($_POST) === false){

//check where to start uploading pictures
$image_name = $_FILES['editcar_fileupload']['name'];
$image_size = $_FILES['editcar_fileupload']['size'];
$image_temp = $_FILES['editcar_fileupload']['tmp_name'];
$allowed_ext = array('jpg','jpeg','png','gif');
$count = count($image_name);

if (isset($image_name) && empty($image_name) === false){
 foreach($image_name as $image_names){
 $image_ext = strtolower(end(explode('.', $image_names)));
 if(in_array($image_ext, $allowed_ext) === false && $true === true){
 $errors[] = 'File type is not allowed';
 }
 }
 if($count > 10){
 $errors[] = 'You can not upload more than 10 pictures for your car.';
 }
}


}

here is the html

<input type="file"  onchange="this.form.editcar_fakeinput.value = this.value;" name="editcar_fileupload[]" multiple="multiple" id="editcar_fileupload" />

it says the $image_name has values in it but it really dosent.

Edited by krash11554
Link to comment
Share on other sites

could check to see if the field is empty?

 

The HTML:

 

<html>
<form action="" method="POST" enctype="multipart/form-data">
<label>File Upload</label><input type="file" name="file" />
<input type="submit" name="submit" value="Upload" />
</form>
</html>

 

The PHP:

 

<?php
if(!$_POST["file"]){
echo "No file selected.";
}else{

//processing code

}
?>

Edited by White_Lily
Link to comment
Share on other sites

Sigh.

I suggest to use empty() instead of isset()

Won't work.

The $_FILES array will be set and not empty for most of the possible error conditions. You must test if the file was actually uploaded, the ['error'] element is set and equal to zero, before you can access any of the uploaded file information.

^ THIS

could check to see if the field is empty?

<?php
if(!$_POST["file"]){
echo "No file selected.";
}else{

//processing code

}
?>

Won't work.

Link to comment
Share on other sites

I have errror 4 which is no file is selected but how come it passes the isset()? if there is no file selected??

 

If you saw a value of 4 in the error element - $_FILES['editcar_fileupload']['error'], wouldn't that mean that $_FILES['editcar_fileupload'] ISSET?

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.