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
https://forums.phpfreaks.com/topic/177333-php-upload/#findComment-935287
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
https://forums.phpfreaks.com/topic/177333-php-upload/#findComment-936664
Share on other sites

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.