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