Jump to content

Recommended Posts

When I upload files larger than appx 18M it says that the file was uploaded but it isnt. Is there snippet of code that i could put in the script to show me the upload error ? Or does anyone know what could be causing this. My php.ini settings are as follows

 

max upload size = 50M

max post size = 100M

execution time = 2400

input time = 2400

 

I thought initially maybe it was timing out so i increased the input and the execution time value. But its still doing the same thing.

-SB

Link to comment
https://forums.phpfreaks.com/topic/246557-new-upload-problem/
Share on other sites

When I upload files larger than appx 18M it says that the file was uploaded but it isnt. Is there snippet of code that i could put in the script to show me the upload error ? Or does anyone know what could be causing this. My php.ini settings are as follows

 

If files smaller than 18M are uploaded without issue it is unlikely to be a problem with your script. More likely an environment variable. What kind of hosting are you using? Can you post the code so we can see where to put the checks in for a successful upload.

Link to comment
https://forums.phpfreaks.com/topic/246557-new-upload-problem/#findComment-1266036
Share on other sites

Hey thanks for the reply. First question whats an envrionment variable? Second, I am hosting this on a homemade LAMP server. Heres the code.

upload.php

$db_host = 'localhost'; // don't forget to change 
$db_user = 'root'; 
$db_pwd = 'dbpass';
$database = 'dbname';
$table = 'videos';
// use the same name as SQL table
$password = '123';
// simple upload restriction,
// to disallow uploading to everyone
if (!mysql_connect($db_host, $db_user, $db_pwd))    
die("Can't connect to database");
if (!mysql_select_db($database))    
die("Can't select database");
// This function makes usage of
// $_GET, $_POST, etc... variables
// completly safe in SQL queries
function sql_safe($s){    
if (get_magic_quotes_gpc())        $s = stripslashes($s);    
return mysql_real_escape_string($s);}
// If user pressed submit in one of the forms
if ($_SERVER['REQUEST_METHOD'] == 'POST'){    
// cleaning title field    
$title = trim(sql_safe($_POST['title']));
if ($title == '') 
// if title is not set        
$title = '(empty title)';
// use (empty title) string    
if ($_POST['password'] != $password)// cheking passwors        
$msg = 'Error: wrong upload password';
else    {        
if (isset($_FILES['movie']))        {            list(, , $mtype, ) = getimagesize($_FILES['movie']['tmp_name']);            
// Get file type.
// We use @ to omit errors
{                $data = file_get_contents($_FILES['movie']['tmp_name']);
$data = mysql_real_escape_string($data);
// Preparing data to be used in MySQL query                
mysql_query("INSERT INTO {$table}                                SET title='$title', movie='$data'");
$msg = 'Success: Video uploaded';
}
}
elseif (isset($_GET['title']))      // isset(..title) needed
$msg = 'Error: file not loaded';
// to make sure we've using
// upload form, not form
// for deletion
if (isset($_POST['del'])) 
// If used selected some video to delete        
{                         
// in 'uploaded videos form'
$id = intval($_POST['del']);
mysql_query("DELETE FROM {$table} WHERE id=$id");
$msg = 'Video deleted';
}    
}
}
elseif (isset($_GET['show'])){    $id = intval($_GET['show']);
$result = mysql_query("SELECT id, UNIX_TIMESTAMP(movie_time), movie FROM {$table}                            WHERE id=$id LIMIT 1");
if (mysql_num_rows($result) == 0)        die('no video');
    list($ext, $movie_time, $data) = mysql_fetch_row($result);    $send_304 = false;    if (php_sapi_name() == 'apache') {
// if our web server is apache
// we get check HTTP        
// If-Modified-Since header
// and do not send image        
// if there is a cached version
$ar = apache_request_headers();
if (isset($ar['If-Modified-Since']) && 
// If-Modified-Since should exists            
($ar['If-Modified-Since'] != '') && 
// not empty            
(strtotime($ar['If-Modified-Since']) >= $movie_time)) 
// and grater than            
$send_304 = true;                                     
// image_time    
}    
if ($send_304)    {        
// Sending 304 response to browser        
// "Browser, your cached version of image is OK        
// we're not sending anything new to you"        
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ts).' GMT', true, 304);        
exit(); 
// bye-bye    
}    
// outputing Last-Modified header    
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $movie_time).' GMT',            true, 200);    // Set expiration time +1 year    
// We do not have any photo re-uploading  
// so, browser may cache this photo for quite a long time    
header('Expires: '.gmdate('D, d M Y H:i:s',  $movie_time + 86400*365).' GMT',            true, 200);    
// outputing HTTP headers    
header('Content-Length: '.strlen($data));    
header("Content-type: video/mpeg");    
// outputing book    
echo $data;    
exit();
}
?>
<head>
<title>MySQL Blob video Gallery Example</title>
<link rel="stylesheet" type="text/css" href="test.css"/>
</head>
<html>
<body>
<?php
if (isset($msg)) 
// this is special section for
// outputing message
{
?>
    <p style="font-weight: bold;"><?=$msg?><br><a href="<?=$_SERVER['PHP_SELF']?>">reload page</a><!-- I've added reloading link, because     refreshing POST queries is not good idea --></p>
    <?php
    }
?>
    <h1>Videos</h1>
    <h2>Uploaded Videos:</h2>
    <form action="<? $_SERVER['PHP_SELF'] ?>" method="post">
    <!-- This form is used for video deletion -->
    <?php
    $result = mysql_query("SELECT id, movie_time, title FROM {$table} ORDER BY id DESC");
if (mysql_num_rows($result) == 0) 
// table is empty    
echo '<ul><li>No Videos Loaded</li></ul>';
else{    
echo '<ul>';    
while(list($id, $movie_time, $title) = mysql_fetch_row($result))    {        
// outputing list        
echo "<li><input type='radio' name='del' value='{$id}'>";        
echo "<a href='{$_SERVER['PHP_SELF']}?show={$id}'>{$title}</a> – ";        
echo "<small>{$movie_time}</small></li>";    
}    
echo '</ul>';    
echo '<label for="password">Password:</label><br>';    
echo '<input type="password" name="password" id="password"><br><br>';    
echo '<input type="submit" value="Delete selected">';
}
?>
    <html>
    <body>
    </form><h2>Upload New Video:</h2><form action="<? $_SERVER['PHP_SELF'] ?>" method="POST" enctype="multipart/form-data">
    <INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="100000000">
    <label for="title">Title:</label><br><input type="text" name="title" id="title" size="64"><br>
    <br>
    <label for="movie">Video:</label><br><input type="file" name="movie" id="movie"><br>
    <br>
    <label for="password">Password:</label><br><input type="password" name="password" id="password"><br>
    <br><input type="submit" value="upload"></form>
    </body>
    </html>

-SB

Link to comment
https://forums.phpfreaks.com/topic/246557-new-upload-problem/#findComment-1266041
Share on other sites

OK, you have some issues here. You are not uploading a file, you are taking the file contents from the $_FILES POST array and attempting to store in the database. You should not do this. When you upload a file you should store the actual file on the server. The only thing that you should store in the database is the filename so that you can target it in whatever element (image, flash object, href, etc).

 

Here is a link to a simple file upload script. If you still have a problem then you need to check that your environment variables are correct. EV are the variables set in your php.ini

 

http://php.about.com/od/advancedphp/ss/php_file_upload.htm

 

Very good info on EV

http://www.sitepoint.com/upload-large-files-in-php/

 

If you are uploading files of such a large size, the regular POST method is not the best choice as you would be sat waiting for the browser to finish loading for a long while. Most users would think that the browser has crashed when it is still sending POST data. The server would most probably timeout. A combination of PHP / Ajax / PERL is a good solution where you do not need to set any variables such as upload_max_filesize or max_execution_time. The uploader I would recommend is uber uploader. See if you can get it working on your server. You will need to read the documentation.

 

http://uber-uploader.sourceforge.net/

 

Link to comment
https://forums.phpfreaks.com/topic/246557-new-upload-problem/#findComment-1266241
Share on other sites

Hey neil thanks for responding...I do indeed want to store the files in LONGBLOB format inside my mysql database. I have done so quite happily with the exact script on other sites for uppload pictures and as i mentioned it works on some videos as large as 18mb (perhaps larger i just dont have a video between 18 and 24mb). I checked my phpinfo() and my suhosin limits were all undesirably low so modified them n restarted apache but its not detecting the changes when i reload phpinfo(). Thoughts?

-SB

Link to comment
https://forums.phpfreaks.com/topic/246557-new-upload-problem/#findComment-1266295
Share on other sites

Check the path to the ini file that is displayed on screen via phpinfo(). Are you ammending the correct file? If so you should post this issue over at the apache or linux board as I would be stabbing in the dark at this one.

 

On another note, the reason that using your database to store the contents of a file is a bad idea is because a mysql database should be optimised for quick reads & writes, especially with websites. Using that sort of data type will result in really poor performance if the table were to become very large. Also, managing the files will be a pain because you cannot actually physically move them or a portion of them. On a video tube website (i'm sure you know many) the actual video file data will never be stored in a database, nor user uploaded images. With the number of files that are served on these sites they would grind to a halt. The physical files will be stored on a CDN, something else to look at if you are making these sort of sites. I am not saying that you should go changing all of your websites, however it is something to consider in future projects.

Link to comment
https://forums.phpfreaks.com/topic/246557-new-upload-problem/#findComment-1266348
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.