Jump to content

Upload Script


ChaosKnight

Recommended Posts

Yesterday I had a lot of drama with creating a file uploader, but it finally works... Now I had to make alternatives to the file upload, because every hotel has a lot of properties and I don't want to have a hundred or so files of the same image, so I inserted this in the form:

<input type="text" id="logoExists" name="logoExists" />

And this PHP code to handle the extra field:

if(isset($_POST['submit'])){
  $logoExists = $_POST['logoExists'];

  $allowedExtensions = array("png","jpg","jpeg","gif");

  if(($logoExists = '')||($logoExists = null)){
    if((isset($_FILES['logo']))&&($_FILES['logo']['tmp_name'] > '')){
      if(!in_array(end(explode(".",strtolower($_FILES['logo']['name']))),$allowedExtensions)){
        die($_FILES['logo']['name'].' has an invalid file type...<br/>');
      }else{
        $target_path = "images/logos/";
        $target_path = $target_path . basename($_FILES['logo']['name']);
        if(move_uploaded_file($_FILES['logo']['tmp_name'], $target_path)){
          echo "<h3>{$_FILES['logo']['name']} uploaded successfully...</h3><br />";
          $logo = $_FILES['logo']['name'];
        }else{
          echo "<h3>{$_FILES['logo']['name']} could not be uploaded...</h3><br />";
        }
      }
    }
  }else{
    $logo = $logoExists;
  }

But it seems like when I leave out the file and insert the text into the logoExists field, that PHP simply ignores all that PHP code...

 

Can anyone see my mistake??  :confused:

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/203179-upload-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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