Jump to content

Upload a file from localdisk


sunilmadhav

Recommended Posts

Hi all,

 

How can i upload a file from the local disk. I normally update the file using

 

$query= "LOAD DATA INFILE 'rondo/nielsen_test.txt' REPLACE INTO TABLE $table FIELDS TERMINATED BY '\\t' LINES TERMINATED BY '\\r\\n';";

 

but i have many file to update. how cani make this statement same for all the file so i can just browse from my computer and update it..

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/188436-upload-a-file-from-localdisk/
Share on other sites

Do you really store files in your database???

Doesn't this overload your database?

 

I personaly like to upload the file to a folder on my ftp server

and store the filename in my database. I think this is a much better way to do this.

 

Here's an example of how I do this:

 

//check if theres a file upload 
if(isset($_FILES['picture_file'])) {
    //if the filesize is larger than 5024000 bytes(100kb) not allowed
    if($_FILES['picture_file']['size'] > 5024000) {
        echo "The imagesize = <b>" . $_FILES['picture_file']['size'] . "</b>, maximum allowed <b>5024000bytes</b>";
    } else {
        //Check if it's an gif,png,jpeg
        if($_FILES['picture_file']['type'] == "image/gif" || 
        $_FILES['picture_file']['type'] == "image/png"  || 
        $_FILES['picture_file']['type'] == "image/pjpeg" || 
        $_FILES['picture_file']['type'] == "image/jpeg") 
        {
         $picture_filename = $_FILES['picture_file']['name'];
         $picture_cid = $_POST['picture_cid'];
 $picture_scid = $_POST['picture_scid'];
         $picture_title = $_POST['picture_title'];

         $query = "INSERT INTO pictures (picture_title, picture_filename, picture_scid, picture_cid) 
         VALUES   ('$picture_title','$picture_filename','$picture_scid','$picture_cid')";
         mysql_query($query)or die(mysql_error());
         //When the data is stored we take care of the file itselve.
         move_uploaded_file($_FILES['picture_file']['tmp_name'], "uploads/pictures/" . $picture_filename);
         //for linux or unix hosts chmod the file to 0777 so anyone can see it.
         chmod("uploads/pictures/" . $picture_filename, 0777);
         // upload finished and now go to index. or another page as you desire.
         header("Location:index.php");
        } else {
            echo("The file is not a: png, jpg of gif");
        }
    }
} else {
// when no file upload we show the form.
$ctitle = "Pictures";
$query = "SELECT * FROM categories WHERE ctitle='$ctitle' ORDER by cid ASC";
$result = mysql_query($query)or die(mysql_error());
$r = mysql_fetch_array($result)or die(mysql_error());
$cid = $r['cid'];
$ctitle = $r['ctitle'];
echo("
<form action=\"\" method=\"post\" enctype=\"multipart/form-data\">
<fieldset><legend>Add a new picture</legend>
<blockquote>
<input name=\"cid\" type=\"hidden\" value=\"$cid\" />
<dt><label>Selecteer een subcategory</label></dt>
<dd><select name=\"scid\">
");
$query = "SELECT * FROM subcategories WHERE cid='$cid' ORDER BY scid DESC";
$result = mysql_query($query)or die(mysql_error());
while($row = mysql_fetch_array($result)){
$scid = $row['scid'];
$sctitle = $row['sctitle'];
echo("
	<option value=\"$scid\">$sctitle</option>
");
}
echo("
</select></dd>
<dt><label>Bestand: selecteer een bestand</label></dt>
<dd><input type=\"file\" name=\"picture_file\"><br></dd>
<dt><label>Nieuwe bestands naam:</label></dt>
<dd><input type=\"text\" name=\"picture_filename\"><br></dd>
<dt><label>Title</label></dt>
<dd><input type=\"text\" name=\"picture_title\"></dd>
<dd><input type=\"submit\" name=\"submit\" value=\"Upload\"></dd>
</blockquote>
</fieldset>
</form> 
");
}

 

I hope this will help you, i use this for everything i want to upload to my server.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.