My files are not uploading

Woo! Ok. I’m using this sitepoint tutorial as the basis to make a photo gallery: http://www.sitepoint.com/php-gallery-system-minutes/

Earlier, I was at a point where it would get to the uploads.php page after taking a long time to load, and error out that the $_FILES array wasn’t defined. So I went back to my display functions, added in some missing quotes, and added in a missing forms tag. Also erased out all the resizing and checking stuff in upload.php, and just asked it to confirm whether or not anything was getting through. When I try to upload, the page just loads over and over.

function photo_upload_fields(){
    for($i=0;$i <10; $i++){
        echo '<tr><td>Photo: = <input name=\'photofilename[]\' type=\'file\'></td></tr>
             <tr></tr>Caption: <textarea name=\'photocaption[]\' cols=30 rows=2> </textarea><br>';
    }
echo '<input type=\'submit\' name=\'submit\'  value=\'Add Photos\'></table></form>';
}

function display_preupload_forms(){ echo '
<html>
<head>
    <title>Upload Photos</title>
</head>
<body>
<form enctype=\'multipart/form-data\'  action=\'upload.php\' method=\'post\'  name=\'upload_form\'>
<tr><td>';
photo_upload_fields();


 echo   '</td></tr>';
}

These are the display functions that get called in preupload.php

require $_SERVER['DOCUMENT_ROOT'] . '\gallery\functions/db_fns.php';
require $_SERVER['DOCUMENT_ROOT'] . '\gallery\functions/display_fns.php';

display_preupload_forms();

This is the actual page that displays the forms.

require $_SERVER['DOCUMENT_ROOT'] . '/gallery/functions/db_fns.php';
if(isset($_FILES['photofilename'])) {
    $photo_file_list = $_FILES['photofilename'];
    echo 'File upload success!';
}
    else {
        echo 'File upload failed.';
    }

if(isset($_POST['photocaption'])) {
    $photo_cap_lists = $_POST['photocaptions'];
}

It’s suppose to check if the $_FILES array has something, and if so, echo out confirmation.

I dont see anything in there that would be looping… but you mention something called “preupload.php” and i dont… see a reference to that file in any of your other codeblocks… so you’re not showing us something.

My bad. Preupload file is just where I call the display_preupload_forms() function

require $_SERVER['DOCUMENT_ROOT'] . '\gallery\functions/db_fns.php';
require $_SERVER['DOCUMENT_ROOT'] . '\gallery\functions/display_fns.php';

display_preupload_forms();

And I see what was causing it, but still don’t understand. I left some stuff out I had in because thought it wouldn’t make a difference but it did.

// List of our known photo types
$known_photo_types = array(
    'image/pjpeg' => 'jpg',
    'image/jpeg' => 'jpg',
    'image/gif' => 'gif',
    'image/bmp' => 'bmp',
    'image/x-png' => 'png'
);

// GD Function List
$gd_function_suffix = array(
    'image/pjpeg' => 'JPEG',
    'image/jpeg' => 'JPEG',
    'image/gif' => 'GIF',
    'image/bmp' => 'WBMP',
    'image/x-png' => 'PNG'
);
//The counter variable again, but this time it's going to be used for error checking.

$photo_counter = 0;

if(isset($_FILES['photofilename'])) {
    $photo_file_list = $_FILES['photofilename'];
    echo 'File upload success!';
}
    else {
        echo 'File upload failed.';
    }

if(isset($_POST['photocaption'])) {
    $photo_cap_lists = $_POST['photocaptions'];
}

full upload.php code. when I take out the array,and the photo_counter initializations, it works.

So the bottom block is upload.php?

How big of a file are you pushing?

Why does upload.php define arrays that it doesnt use?

Be aware when using that tutorial that the mysql_* functions that it uses have been deprecated as of version 5.5 of PHP and are being removed from version 7 of PHP

it does use those arrays. i just went ahead and deleted the code that used it. but even when i did have that code up, i was still getting the the forever loading.

yeah. i replaced most of them with their pdo equivalent

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.