karatekid36 Posted May 18, 2007 Share Posted May 18, 2007 This is the first time I have worked with uploading files through and html form with php. I can not see why this is not working. I used this form once and it worked and then I started adding some other things to the file and of course it does not want to move the file properly anymore. I just can not see why it is not working anymore. If anyone spots something please let me know.... <?php session_name ('YourVisitID'); session_start(); // Start the session. // If no session value is present, redirect the user. if (!isset($_SESSION['user_id'])) { // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } $url .= '/index.php'; // Add the page. header("Location: $url"); exit(); // Quit the script. } $page_title = 'Upload Awards or Paddles'; include('./includes/header.html'); $counter = 1; if(isset($_POST['submitted'])) { require_once('./includes/mysql_connect.php'); for($i = 0; $i < $counter; $i++) { $filename = 'upload' . $i; $description = 'description' . $i; $pledge_class = 'pledge_class'; if(isset($_FILES[$filename]) && ($_FILES[$filename]['error'] !=4)) { if(!empty($_POST[$description])) { $d = "'" . escape_data($_POST[$description]) . "'"; } else { $d = 'NULL'; } $query = "INSERT INTO ap_uploads (pledge_class, file_name, file_size, file_type, description) VALUES ($pledge_class, '{$_FILES[$filename]['name']}', '{$_FILES[$filename]['size']}', '{$_FILES[$filename]['type']}', $d)"; $result = mysql_query ($query); if($result) { $upload_id = mysql_insert_id(); if(move_uploaded_file($_FILES[$filename]['tmp_name'], "awards_paddles_img/$upload_id")) { echo '<p>File number ' . ($i + 1) . ' has been uploaded!</p>'; } else { echo '<p><font color="red">File number ' . ($i +1) . 'could not be moved.</font></p>'; $query = "DELETE FROM ap_uploads WHERE upload_id = $upload_id"; $result = mysql_query($query); } } else { echo '<p><font color="red"> Your submission could not be processed due to a system error.</font></p>'; } } } mysql_close(); } ?> <form enctype="multipart/form-data" action="upload_ap_images.php" method="post"> <fieldset><legend>Fill out the form to upload the image:</legend> <input type="hidden" name="MAX_FILE_SIZE" value="524288" /> <br /> <p><b>Please Make Sure That There Are No Spaces In The File Name.</b></p> <p>For Example, the filename picture 1.jpeg is not correct. The filename picture1.jpeg or picture_1.jpeg is correct.</p> <br /> <?php for ($i = 0; $i < $counter; $i++) { ?><p>Pledge Class:<?php // Make the pledge class array. $pledgeclass = array (1 => 'FF', 'Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta', 'Theta', 'Iota', 'Kappa', 'Lambda', 'Mu', 'Nu', 'Xi', 'Omicron', 'Pi', 'Rho', 'Sigma', 'Tau', 'Upsilon', 'Phi', 'Chi', 'Psi', 'Omega'); // Make the pledge class pull-down menu. echo '<select name="pledge_class">'; echo "<option value=\"\">Select Pledge Class</option>\n"; foreach ($pledgeclass as $key => $value) { echo "<option value=\"$value\">$value</option>\n"; } echo '</select>'; ?></p><?php echo ' <p><b>File:</b> <input type="file" name="upload' . $i . '" /></p> <p><b>Description:</b><br /> <textarea name="description' . $i . '" cols="40" rows="5"></textarea></p><br /> '; } ?> </fieldset> <input type="hidden" name="submitted" value="TRUE" /> <div align="center"><input type="submit" name="submit" value="Upload Images" /></div> </form> <?php include ('./includes/footer.html'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52016-i-am-curious-why-my-uploaded-image-is-not-going-to-the-proper-folder/ Share on other sites More sharing options...
karatekid36 Posted May 18, 2007 Author Share Posted May 18, 2007 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/52016-i-am-curious-why-my-uploaded-image-is-not-going-to-the-proper-folder/#findComment-256474 Share on other sites More sharing options...
shadowmonk Posted May 18, 2007 Share Posted May 18, 2007 I had this happen recently, you could try doing an absolute link. Then, once you verify it's working you can migrate to the relative if you really need to. You might also make sure the folder has write permissions. Quote Link to comment https://forums.phpfreaks.com/topic/52016-i-am-curious-why-my-uploaded-image-is-not-going-to-the-proper-folder/#findComment-256493 Share on other sites More sharing options...
karatekid36 Posted May 18, 2007 Author Share Posted May 18, 2007 I checked the permissions and they we not correct. I have since changed them to the proper permissions, but still it is not moving the file properly. I also changed it to an absolute link and they only produced an error. If anyone else has any other suggestions please let me know. Quote Link to comment https://forums.phpfreaks.com/topic/52016-i-am-curious-why-my-uploaded-image-is-not-going-to-the-proper-folder/#findComment-256680 Share on other sites More sharing options...
hitman6003 Posted May 18, 2007 Share Posted May 18, 2007 May not help, but force the script to recognize that you mean "the current directory" by prepending "./" to the folder name: move_uploaded_file($_FILES[$filename]['tmp_name'], "./awards_paddles_img/$upload_id") Is it moving the file at all, or is it moving it to an incorrect location? Quote Link to comment https://forums.phpfreaks.com/topic/52016-i-am-curious-why-my-uploaded-image-is-not-going-to-the-proper-folder/#findComment-256684 Share on other sites More sharing options...
karatekid36 Posted May 18, 2007 Author Share Posted May 18, 2007 I added that and it sill does not work. It is not moving the file to anywhere on my server! This is starting to drive me nuts! So to answer your question, not only is it not going to the right directory, it is not going to the server at all.... Quote Link to comment https://forums.phpfreaks.com/topic/52016-i-am-curious-why-my-uploaded-image-is-not-going-to-the-proper-folder/#findComment-256691 Share on other sites More sharing options...
john010117 Posted May 18, 2007 Share Posted May 18, 2007 Put error_reporting(E_ALL); at the very top of your script (after session_start()), and see what it produces. Quote Link to comment https://forums.phpfreaks.com/topic/52016-i-am-curious-why-my-uploaded-image-is-not-going-to-the-proper-folder/#findComment-256695 Share on other sites More sharing options...
karatekid36 Posted May 18, 2007 Author Share Posted May 18, 2007 I added that to the top and nothing happened when i reloaded it in my browser or when i resubmitted the form. Quote Link to comment https://forums.phpfreaks.com/topic/52016-i-am-curious-why-my-uploaded-image-is-not-going-to-the-proper-folder/#findComment-256697 Share on other sites More sharing options...
hitman6003 Posted May 18, 2007 Share Posted May 18, 2007 Make sure display errors is on too... ini_set("display_errors", 1); ...just after John's code. Quote Link to comment https://forums.phpfreaks.com/topic/52016-i-am-curious-why-my-uploaded-image-is-not-going-to-the-proper-folder/#findComment-256702 Share on other sites More sharing options...
karatekid36 Posted May 18, 2007 Author Share Posted May 18, 2007 still nothing Quote Link to comment https://forums.phpfreaks.com/topic/52016-i-am-curious-why-my-uploaded-image-is-not-going-to-the-proper-folder/#findComment-256704 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.