El Chupacodra Posted January 18, 2012 Share Posted January 18, 2012 I have a page for image uploads and I just realized it will only work if a user already has on picture uploaded. If they don't it won't work. The ones that do fail some photos anyway which is probably that they don't pass the image check but when I put echoes in there to trace what happens any user with an empty gallery can't upload a photo because the page says there is no file in the $_FILES['image']['name'] variable. Here are the initial conditions and the form (leaving out the image processing etc since that works): if (!isset($_SESSION['user'])) die("<br /><br /> You need to log in to view this page"); $user = sanitizeString($_SESSION['user']); $view = sanitizeString($_GET['view']); $dir = './grafik/users/'.$user.'/big/'; $files = scandir($dir); $len = count($files); $nr= $len-1; $maxPhotos = 8; if ($view == $user) { echo "view is user"; if(!file_exists("grafik/users/$user")) { mkdir("grafik/users/$user"); mkdir("grafik/users/$user/big/");} } if (!isset($_FILES['image']['name'])) echo "There is no file <br />$dir - $user - $nr"; if (isset($_FILES['image']['name'])) { echo "<br />...is a file <br />$dir - $user - $nr"; $photoName="$dir$user$nr.jpg"; move_uploaded_file($_FILES['image']['tmp_name'], $photoName); $typeok = TRUE; .... <form method='post' action='gallery.php?view=$user' enctype='multipart/form-data'> Upload another photo: <br /> Max $maxPhotos allowed, max filesize 2Mb <br /> <input type='file' name='image' size='10' /><br /> <input type='submit' value='Upload' /> </form> I can't see why it wouldn't let me but I have a feeling someone here knows why. Link to comment https://forums.phpfreaks.com/topic/255313-upload-photos-odd-problem/ Share on other sites More sharing options...
Pikachu2000 Posted January 19, 2012 Share Posted January 19, 2012 Checking for errors in the $_FILES array may help illuminate why the filename is empty. http://php.net/manual/en/features.file-upload.errors.php Link to comment https://forums.phpfreaks.com/topic/255313-upload-photos-odd-problem/#findComment-1309130 Share on other sites More sharing options...
El Chupacodra Posted January 19, 2012 Author Share Posted January 19, 2012 Thanks for the tip - it helped me solve why another file couldn't be used. It was error code 1 - file size. As for this one it just won't pick up that there is a file selected so it never starts loading the file. My indicator also signals that no file is set in the form. I will strip out my conditionals one by one and see if it works better without all of them. Link to comment https://forums.phpfreaks.com/topic/255313-upload-photos-odd-problem/#findComment-1309308 Share on other sites More sharing options...
El Chupacodra Posted January 19, 2012 Author Share Posted January 19, 2012 Found the problem but it was nowhere near where I thought. It's a div I had to format the output of the photos in the gallery. Weird but when the php is in a different div from the upload form it apparently works if there is a file uploaded already but not if the gallery is empty. I'll try and remember that the next time I have a problem like this. Thanks for the $_FILES Error tip, will be useful in the form for the same page. Link to comment https://forums.phpfreaks.com/topic/255313-upload-photos-odd-problem/#findComment-1309323 Share on other sites More sharing options...
Pikachu2000 Posted January 19, 2012 Share Posted January 19, 2012 I'm glad you were able to figure it out. Link to comment https://forums.phpfreaks.com/topic/255313-upload-photos-odd-problem/#findComment-1309373 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.