Jump to content

can't upload file ????


aabid

Recommended Posts

Hey guys,

I don't know why but i am not able to get my file uploaded to the particular directory nor its being shown in the temporary directory.

Please have a review on this code and let me know what am i doing wrong with it, I am using xampp for testing purpose.

 

<?php
include('headlay.inc');
include('dbinfo.inc');
class uploadfile
{
public $songname;
public $download_link;

function show_form()
	{
	if(isset($_POST[upload]))
		{
		$destination = 'songs/'.$_FILES['get_song']['name'];
		echo $_FILES['get_song']['tmp_name'];
		move_uploaded_file($_FILES['get_song']['tmp_name'], $destination);
		echo "<tr><td> Songs has been uploaded succesfully, You can upload another one now.</td></tr>";
		$this->songname = $_POST[songname];
		$this->download_link = $destination;
		$this->save_to_db();
		$this->ul_form();
		}
		else
		{
		$this->ul_form();
		}
	}

function ul_form()
	{
	echo "<form action='$_SERVER[php_SELF]' enctype='multipart/form-data' method='POST'>
	<input type='hidden' name='max_file_size' value='10240' />
	<tr>
	<td>Enter Song Name: <input type='text' name='songname' /></td>
	</tr>
	<tr>
	<td>Select File: <input type='file' name='get_song' /></td>
	</tr>
	<tr>
	<td align='center'><input type='submit' name='upload' value='Upload Song' /></td>
	</tr>";
	}

function save_to_db()
	{
	$connect = mysql_connect($host, $dbuser, $dbpass);
	mysql_select_db($dbname, $connect);
	$sql = "insert INTO SONGS ('songname', 'download_link') VALUES ($this->songname, $this->download_link)";
	mysql_query($sql, $connect);
	}

}

echo "<table>";
$upload = new uploadfile();
$upload->show_form();
echo "</table>";
include('footlay.inc');
?>

Link to comment
Share on other sites

IT SEEMS THAT IT IS WORKING FOR SMALL FILES LIKE TEXT FILES BUT WHEN I TRY TO UPLOAD ANY MP3 OF 4-5 MB THAN IT JUST DOESN'T SHOWS UP THERE.

 

I have increased the max_file_size into 8 digits but then also it didn't shows up, as far as the code is concerned it is working correctly for small files which are of few KB's.

The problem is with big files i think......plz help

Link to comment
Share on other sites

Your code has absolutely no error checking logic in it to test if the upload worked before you attempt to access any of the uploaded file information. At a minimum you need to test that the $_FILES array is set (use isset($_FILES) and that $_FILES['get_song']['error'] is a zero value -

UPLOAD_ERR_OK

Value: 0; There is no error, the file uploaded with success.

 

Please read the upload handling section of the php.net documentation - http://us.php.net/manual/en/features.file-upload.php

 

 

Link to comment
Share on other sites

Its working with small text files that i checked but the problem exist with *.mp3 file (or you can say with big files), So I am sure there is something with the configuration which is not allowing that file to be uploaded.

 

I checked the $_FILES with print_r and it displays 2 as error code, don't know what it means ????

Link to comment
Share on other sites

The information at the link I posted above tells you what that error means.

 

There's at least three different size related errors ($_FILES will be empty for one of them and you will get an error value of 1 or 2 for the other two) and there's a handful of other errors that can occur that are out of your hands, such as the visitor not selecting a file or aborting the upload part way through.

 

If you are not going to put error checking logic in your code to get your code to only process the uploaded file when it has been successfully uploaded, you are going to constantly be faced with code that does not work under some conditions. No matter what you change the settings to, someone CAN and WILL attempt to upload a file that is larger than what the settings are and if you set them to outrageously large values, some hacker is going to use that to bog down your server and get your account suspended by constantly uploading huge files.

 

Make your code user and server friendly by using error checking logic in it.

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.