Jump to content

Script does not upload any files


WilliamNova

Recommended Posts

So I'm making an upload file for my website for users to upload images. However, it's not working and I have no clue why. This is the entire php script for this page becuase I'm not sure what could be causing it.

<?php
include ( './includes/header.php' );

if (isset($_FILES['channel_pic'])) {
   if (($_FILES['channel_pic']['type']=='image/jpeg') || ($_FILES['channel_pic']['type']=='image/png') || $_FILES['channel_pic']['type']=='image/gif') {
   $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';                                                                             
   $random_directory = substr(str_shuffle($chars), 0, 15);

   if (file_exists('data/channels/images/icons/' . $random_directory . ''.$_FILES['channel_pic']['name'])) {
     echo 'image exists';
   }
   else
   {
   move_uploaded_file($_FILES['channel_pic']['tmp_name'],'data/channels/images/icons/' . $random_directory . ''.$_FILES['channel_pic']['name']);

   }
   }
   if (($_FILES['channel_pic']['type']=='image/jpeg') || ($_FILES['channel_pic']['type']=='image/png') || $_FILES['channel_pic']['type']=='image/gif') {

   }
   else
   {
    die('Invalid File'); 
   }

}
?>

So, let's see. The die function won't work when I upload, say a .RAW format. And it should upload any jpeg's, png's, or gif's to a randomly created directory. Which it's not doing. The folders do exist --> data/channels/images/icons

Link to comment
Share on other sites

the $_FILES array is empty when you try to upload a file that is larger than the post_max_size setting. $_FILES['channel_pic'] won't be set and all your code is bypassed. you need to test for this condition first.

 

next, even if you upload a file smaller than the post_max_size setting, the upload can fail with an error. you must test if $_FILES['channel_pic']['error'] is set and equal to (an == comparison) a zero to insure that the upload actually worked. you can also test if $_FILES['channel_pic']['error'] is exactly equal to (an === comparison) a zero to combine both tests into one.

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.