Jump to content

PHP upload


Superman911

Recommended Posts

I would avoid storing blobs in mysql due to the substantial overhead of getting the file data into/out of the database.  In essence this is double the overhead of just storing it on the PHP server, although if you have a cluster of servers, this can also become a problem.

 

As for PHP, it uses the $_FILES superglobal to store information about the HTTP post that includes the uploaded file.  PHP sticks it in a temp directory, and it's up to you to call move_uploaded_file() and give the file a permanent name and location.

 

Typically this is where people store the location of the file in a database.

 

There's plenty more to be said about this topic, however as for a few tips and places to read, I think this should get you going.

Link to comment
Share on other sites

Hey all.

 

I am using the following to upload the files now, but would like to rename the file before saving it, can any body help me with this.

<?php

if(isset($_POST['upload']) && $_FILES['userfile']['size'] >
0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content =addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc()){
  
    $fileName = addslashes($fileName);
}

include 'opendb.php';

$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');


echo "<br>File $fileName uploaded<br>";

}
?>

Many thanks

 

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.