Jump to content

Upload File Problem


june_c21

Recommended Posts

hi, i am doing a page where user need add their material into c:\PI. I try to run this system. It didn't not show any error but it fail to upload the file to c:\PI. Anything wrong? Can someone show me the error? thanks

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Drawing Database</title>
<style type="text/css">
<!--
body {
background-color: #0066FF;
}
.style6 {font-family: "Arial Black"; font-size: 12px; }
-->
</style></head>

<body>
<p> </p>
<p> </p>
<p> </p>
<form action="add.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <p align="center" class="style6">Add</p>
  <table width="194" border="1" align="center">
    <tr>
      <td width="157"><span class="style6">GF</span></td>
      <td width="11"><span class="style6">:</span></td>
      <td width="8"><label>
        <select name="gf" id="gf">
          <option value="gf1">GF1</option>
          <option value="gf2">GF2</option>
          <option value="gf3">GF3</option>
          <option value="gf4">GF4</option>
          <option value="miscellaneous">Miscellaneous</option>
        </select>
      </label></td>
    </tr>
    <tr>
      <td><span class="style6">Drawing No </span></td>
      <td><span class="style6">:</span></td>
      <td><label>
        <input name="drawing_no" type="text" id="drawing_no" />
      </label></td>
    </tr>
    <tr>
      <td><span class="style6">Manufacture No </span></td>
      <td><span class="style6">:</span></td>
      <td><label>
        <input name="manufac_no" type="text" id="manufac_no" />
      </label></td>
    </tr>
    <tr>
      <td><span class="style6">Title</span></td>
      <td><span class="style6">:</span></td>
      <td><label>
        <textarea name="title" id="title"></textarea>
      </label></td>
    </tr>
    <tr>
      <td class="style6">Upload </td>
      <td class="style6">:</td>
      <td><label>
        <input type="file" name="file" />
      </label></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
      <td><label>
      <input type="submit" name="Submit" value="Submit" />
      </label></td>
    </tr>
  </table>
  <p>
    <label></label>
  </p>
</form>
<p> </p>
</body>
</html>

 

 

php code

if ($HTTP_POST_VARS['submit']) 
{ 
    if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])) 
    { 
    $error = "You did not upload a file!"; 
    unlink($HTTP_POST_FILES['file']['tmp_name']); 
    // assign error message, remove uploaded file, redisplay form. 
    } 
    else 
    { 
    //A file was uploaded 
    $maxfilesize=300000; 
        if ($HTTP_POST_FILES['file']['size'] > $maxfilesize) 
        { 
            $error = "File is too large."; 
            unlink($HTTP_POST_FILES['file']['tmp_name']); 
            // assign error message, remove uploaded file, redisplay form. 
        } 
        else 
        { 
             //File has passed all validation, copy it to the final destination and remove the temporary file: 
             copy($HTTP_POST_FILES['file']['tmp_name'],$HTTP_POST_FILES['file']['name']); 
             unlink($HTTP_POST_FILES['file']['tmp_name']); 
         print "File has been successfully uploaded!"; 
             exit;    
            } 
      } 
} 

$gf    = $_POST['gf'];
$drawing_no = $_POST['drawing_no'];
$manufac_no = $_POST['manufac_no'];
$title = $_POST['title'];

$query= "INSERT INTO drawings( gf,drawing_no,manufac_no,title) VALUES ('$gf', '$drawing_no','$manufac_no','$title') ";
$result = mysql_query($query,$dblink);

Link to comment
Share on other sites

it appears you are not specifying where to copy the image to in this line

 

copy($HTTP_POST_FILES['file']['tmp_name'],$HTTP_POST_FILES['file']['name']);

 

This is my code

 

$idir = "../images/gallery/full/";   // Path To Images Directory 

$_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use 
    if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") { 
        $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php 
        $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location 
            if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location 
       		print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image

Link to comment
Share on other sites

copy($HTTP_POST_FILES['file']['tmp_name'],$HTTP_POST_FILES['file']['name']); 

 

i put it in this way

 

 copy($HTTP_POST_FILES['file']['tmp_name'],$HTTP_POST_FILES['file']['c:/PI']); 

 

but it stil doesn't work. Why ?

 

AdRock, I a bit blur with your code. Can guide me more? thanks

Link to comment
Share on other sites

Can you post your code again?

 

Did you use my exampl eor try using your own?

 

If you used mine any you want to uploads gifs change this

if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {

to

if ($_FILES['imagefile']['type'] == "image/gif" {

Link to comment
Share on other sites

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.