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
https://forums.phpfreaks.com/topic/278588-script-does-not-upload-any-files/
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.

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.