By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,903 Members | 2,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,903 IT Pros & Developers. It's quick & easy.

Newbie Upload Script Help

P: 2
Hello,

I keep getting the following erorrs when trying to use a PHP/MYSQL upload script. Can anyone tell me what's causing this error? I'm not a programmer, just an MFA student working on his thesis and needs to collect images from several thousand people.

So far I have CMOD 777 the directory that uploads are going into and tried different directories but nothing has worked.

Thanks in advance!

Warning: move_uploaded_file(/uploads/011bc55e70e56ea8a320e7182166d67a.JPG): failed to open stream: No such file or directory in /home/content/g/r/o/grozanc/html/pavementmemoirs/uploads/upload3.php on line 42

Warning: move_uploaded_file(): Unable to move '/tmp/phpOuv94S' to '/uploads/011bc55e70e56ea8a320e7182166d67a.JPG' in /home/content/g/r/o/grozanc/html/pavementmemoirs/uploads/upload3.php on line 42
Error uploading file
Here is the code to the script I'm trying to run:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Upload File To MySQL Database</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <style type="text/css">
  6. <!--
  7. .box {
  8.     font-family: Arial, Helvetica, sans-serif;
  9.     font-size: 12px;
  10.     border: 1px solid #000000;
  11. }
  12. -->
  13. </style>
  14. </head>
  15.  
  16. <body>
  17. <?
  18. // you can change this to any directory you want
  19. // as long as php can write to it
  20. $uploadDir = '/uploads/';
  21.  
  22.  
  23. if(isset($_POST['upload']))
  24. {
  25.     $fileName = $_FILES['userfile']['name'];
  26.     $tmpName  = $_FILES['userfile']['tmp_name'];
  27.     $fileSize = $_FILES['userfile']['size'];
  28.     $fileType = $_FILES['userfile']['type'];
  29.  
  30.     // get the file extension first
  31.     $ext      = substr(strrchr($fileName, "."), 1); 
  32.  
  33.     // generate the random file name
  34.     $randName = md5(rand() * time());
  35.  
  36.     // and now we have the unique file name for the upload file
  37.     $filePath = $uploadDir . $randName . '.' . $ext;
  38.  
  39.     // move the files to the specified directory
  40.     // if the upload directory is not writable or
  41.     // something else went wrong $result will be false
  42.     $result    = move_uploaded_file($tmpName, $filePath);
  43.     if (!$result) {
  44.         echo "Error uploading file";
  45.         exit;
  46.     }
  47.  
  48.     include 'library/config.php';
  49.     include 'library/opendb.php';
  50.  
  51.     if(!get_magic_quotes_gpc())
  52.     {
  53.         $fileName  = addslashes($fileName);
  54.         $filePath  = addslashes($filePath);
  55.     }  
  56.  
  57.     $query = "INSERT INTO upload2 (name, size, type, path ) ".
  58.              "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
  59.  
  60.     mysql_query($query) or die('Error, query failed : ' . mysql_error());                    
  61.  
  62.     include 'library/closedb.php';
  63.  
  64.     echo "<br>File uploaded<br>";
  65. }        
  66. ?>
  67. <form action="" method="post" enctype="multipart/form-data" name="uploadform">
  68.   <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
  69.     <tr> 
  70.       <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="200000000"><input name="userfile" type="file" class="box" id="userfile">
  71.          </td>
  72.       <td width="80"><input name="upload" type="submit" class="box" id="upload" value="  Upload  "></td>
  73.     </tr>
  74.   </table>
  75. </form>
  76. </body>
  77. </html>
  78.  
May 20 '07 #1
Share this Question
Share on Google+
2 Replies


P: 2
I got everything working, thanks anyway.
May 20 '07 #2

Atli
Expert 5K+
P: 5,058
I got everything working, thanks anyway.
Hi, grozanc, and welcome to TSDN.

I'm glad to hear you have solved your problem.
Would you be willing to share your solution with us?
May 20 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.