WilliamNova Posted May 30, 2013 Share Posted May 30, 2013 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 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 30, 2013 Share Posted May 30, 2013 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. Quote Link to comment Share on other sites More sharing options...
WilliamNova Posted May 31, 2013 Author Share Posted May 31, 2013 I found the error and I should have looked more closely at my form, which I didn't even think was the problem. <form action='upload_image.php' method='POST' encytype='multipart/form-data'> Spelled enctype wrong. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 31, 2013 Share Posted May 31, 2013 cannot help you with parts of the relevant code you didn't put in your post and spelling errors are not really programming problems anyway. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.