file upload blues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
KSUpride
Forum Newbie
Posts: 5
Joined: Mon Dec 29, 2008 8:37 pm

file upload blues

Post by KSUpride »

Hello Programmers,

I was wondering if anyone could help me. I would like people to upload files to the server from their computer. The problem is whenever the user hits the submit button, I get the following error "Your submission could not be processed due to a system error. We apologize for any inconvenience". What am I doing wrong? Thanks in advance. To be more precise here is the following code.

Code: Select all

 
 
<?php
$page_title = 'Upload a File';
 
 
$counter = 1;
 
if (isset($_POST['submitted'])) {
 
require_once ('../mysql_connect.php');
 
for ($i = 0; $i < $counter; $i++) {
 
 
$filename = 'upload' . $i;
 
 
if (isset($_FILES[$filename])&& ($_FILES[$filename]['error'] != 4)) {
 
 
 
$query = "INSERT INTO resume (file_name, file_size, file_type) VALUES ('{$_FILES[$filename]['name']}', {$_FILES[$filename]['size']}, '{$_FILES[$filename]['type']})";
$result = mysql_query ($query);
 
if ($result) {
 
 
$upload_id = mysql_insert_id();
 
 
if (move_uploaded_file($_FILES[$filename]['tmp_name'], "../uploads/$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 resume 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. We apologize for any inconvenience.</font></p>';
 
}
 
}
 
}
 
mysql_close();
 
}
?>
<form enctype="multipart/form-data" action="add_file.php" method="post">
 
<fieldset><legend>Fill out the form to upload a file:</legend>
<input type="hidden" name="MAX_FILE_SIZE" value="524288">
 
<?php
 
for ($i = 0; $i < $counter; $i++) {
echo '<p><b>File:</b> <input type="file" name="upload' . $i . '" /></p>';
}
?>
 
</fieldset>
<input type="hidden" name="submitted" value="TRUE" />
<div align="center"><input type="submit" name="submit" value="Submit" /></div>
 
</form>
 
 
 


Here is the link to the page to test it.

http://www.rodriguezstudios.com/resume/ ... d_file.php

Thanks in advance.
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: file upload blues

Post by novice4eva »

check your $query, echo it, you must be missing something, a single quote or something like that
KSUpride
Forum Newbie
Posts: 5
Joined: Mon Dec 29, 2008 8:37 pm

Re: file upload blues

Post by KSUpride »

LOL Duh! You are right. I can't believe something that little can cause big problems. Thanks!
Post Reply