Jump to content

Recommended Posts

Hello everyone, I'm trying to make a script that will upload a file to a directory specified by the user and updates a database table with the the name of the file uploaded, the type of file (e.g. firmware, software, docs, ect.), and the product the file is for. but I'm getting these errors:

 

Warning: move_uploaded_file(uploads/1111A/doc/3rdpeak.JPG) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/J/a/p/JapII/html/herb/site/uploader.php on line 181

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpquL7Yg' to 'uploads/1111A/doc/3rdpeak.JPG' in /home/content/J/a/p/JapII/html/herb/site/uploader.php on line 181

 

here are lines 174-223

 <?php
   $product = ($_POST['product_id']);
   $type = ($_POST['type']);
    $path = "uploads/$product/$type/";

    $target_path = $path . basename( $_FILES['uploadedfile']['name']); 
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { // line 181
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    }
    else{
          echo "There was an error uploading the file, please try again!";
        }


?>

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<br/>
Product:<br/>
<?php
         $conn ="SELECT product_id FROM `products`" ;
         $result = mysql_query($conn,$query) or die("Error: ". mysql_error(). " with query ". $conn);
         while($row=mysql_fetch_assoc($result))
          {
           $url[] = $row['product_id'];
          }
          
         echo "<select name='product_id'>\n";
         foreach($url as $y){
                 echo "<option value='$y'>\n" .$y."</option>\n";
                }
         echo "</select>\n";
?>
<br /> <br/>
File Type:<br/>
<select name="type">
<option value="doc">Documentation</option>
<option value="firmware">Firmware</option>
<option value="software">Software</option>
<option value="notif">Notification</option>
<option value="misc">Miscellaneous</option>
</select>
<br/><br/>
<input type="hidden" name="MAX_FILE_SIZE" value="104857600" />
File to upload: <input name="uploadedfile" type="file" /><br />
<br/>
<input type="submit" value="Upload File" />
</form>

 

the database is not being updated either, here the section of code that is supposed to handle that:

<?php
session_start(); 
if(!isset($_SESSION['adminctrl'])){ 
    header('Location: admin.php'); die('<a href="admin.php">Login first!</a>');
   }
$query = mysql_connect("***********.net", "*******", "*********") or die(mysql_error());
mysql_select_db('*******', $query) or die(mysql_error());

$error = array();
if(isset($_POST['name'])) {
$result = @mysql_query('SELECT product_id FROM `product_docs_support` WHERE name = \''.mysql_real_escape_string($_POST['uploadedfile']).'\'');
if($row = @mysql_fetch_row($result)) {
array_push($error, 'Directory is already listed in the Database. Please select another.');
}
$len = strlen($_POST['name']);
if($len < 3 || ($len > 70)) { array_push($error, 'listing must be between 3 and 70 characters long.'); }
@mysql_query('INSERT INTO `product_docs_support` (product_id, type, name) VALUES (\''.mysql_real_escape_string($_POST['product_id']).'\', \''.mysql_real_escape_string($_POST['type']).'\',\''.mysql_real_escape_string($_POST['uploadedfile']).'\')');
if(!$error) {
    echo"Update was successful.";
}
}

?>

 

thanks for any help.

 

Link to comment
https://forums.phpfreaks.com/topic/141121-file-uploader-propblem/
Share on other sites

Any ideas?
You are using @ in your code to suppress php generated errors and you have no error checking logic to test if the INSERT query worked or not, so there is no way for your code to tell you why it did not work.

 

1) Never use @. On a live server set display_errors to OFF so that any php generated errors will still be written to the error log file so that you have a record of when and what is going on.

 

2) An mysql_query for an INSERT query will return a TRUE or FALSE value if the query executed or not. Test that and display an appropriate error message if the query failed. Use an mysql_error() statement for debugging why the query failed.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.