|
-
Oct 11th, 2009, 11:01 AM
#1
Thread Starter
Frenzied Member
Uploading File, Not Working!
Hello, first of all I checked my code on a online syntex checker, so there are no errors with the syntex. The code was based off a website (w3schools) with additions and modifications of my own. I tried changing the path of the upload folder, to a folder within the same directory of the php file, still it didn't work. I changed the file permissions of the folders, still it did not work.
Here is the part of my code that does the upload:
PHP Code:
function filecount($FolderPath) {
$filescount = 0;
// Open the directory
$dir = opendir($FolderPath);
// if the directory doesn't exist return 0
if (!$dir){return 0;}
// Read the directory and get the files
while (($file = readdir($dir)) !== false) {
if (is_dir($FolderPath . $file) == false) {
// Increment the File Count.
$filescount++;
}
}
// close the directory
closedir($dir);
return $filescount;
}
if (($_FILES["mp3File"]["type"] == "audio/mpeg") && ($_FILES["mp3File"]["size"] < 10485760))
{
if ($_FILES["mp3File"]["error"] > 0)
{
//header('Location: ../error_page.php?error=83343');
echo "Return Code: " . $_FILES["mp3File"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["mp3File"]["name"] . "<br />";
echo "Type: " . $_FILES["mp3File"]["type"] . "<br />";
echo "Size: " . ($_FILES["mp3File"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["mp3File"]["tmp_name"] . "<br />";
if (file_exists("../audio/" . $_POST['company'] . "commercials/" . $_FILES["mp3File"]["name"])) {
//header('Location: ../error_page.php?error=83343');
echo $_FILES["mp3File"]["name"] . " already exists. ";
}
else
{
$newFileNameCount = $filecount("../audio/" . $_POST['company'] . "commercials/") + 1;
move_uploaded_file($_FILES["mp3File"]["tmp_name"], "../audio/" . $_POST['company'] . "commercials/" . $_FILES["mp3File"]["name"]);
The PHP page is echoing this piece of code:
PHP Code:
echo "Upload: " . $_FILES["mp3File"]["name"] . "<br />";
echo "Type: " . $_FILES["mp3File"]["type"] . "<br />";
echo "Size: " . ($_FILES["mp3File"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["mp3File"]["tmp_name"] . "<br />";
Then it doesn't process the code that follows..
Here is the HTML that calls the code:
html Code:
<form action="p_customvoicemessage.php" method="post" enctype="multipart/form-data">
<font size="2">Browse for your mp3 file and then click Send Message.</font>
<br />
<input type="file" name="mp3File" id="mp3File" />
<br /><br />
<font size="2">Expiry Date (YYYY-MM-DD):</font><br /><input type="text" name="expiryDate" value='<?php echo date("Y-m-d"); ?>' />
<br /><br/>
<input type="hidden" name="company" value="<?php echo $company; ?>" />
<input type="hidden" name="username" value="<?php echo $_SESSION['username']; ?>" />
<input type="submit" value="Send Message" style="width:50%" />
</form>
-
Oct 11th, 2009, 04:18 PM
#2
Re: Uploading File, Not Working!
you really don't need to keep bumping this!
anyway, I don't want to copy all of your code and try to run it on my server to see if it works (I'm on a short vacation for Thanksgiving!). instead, why don't you run one of these examples from PHP.net on your server and then let us know if they work or not? if not, you may want to talk to your host about file uploads. if they do, then something is wrong with your code -- and I can further help you from there!
-
Oct 11th, 2009, 05:02 PM
#3
Thread Starter
Frenzied Member
Re: Uploading File, Not Working!
Using the examples you linked to this is the result:
Possible file upload attack!
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => Test Announcement.raf
[type] => application/octet-stream
[tmp_name] => /tmp/phpRtU5jT
[error] => 0
[size] => 207
)
)
I changed the path /var/www/uploads/ to uploads/ is that fine? Or does it need to be in var? Since my web pages are in public_html, so I wanted to keep everything in the public_html folder.
-
Oct 11th, 2009, 05:30 PM
#4
Re: Uploading File, Not Working!
that should be fine, I guess.
the error you're getting is that move_uploaded_file() is not working. you could try asking your host about it! if you don't have permission to move files from /tmp/ then I guess that would be the root of the issue.
-
Oct 11th, 2009, 05:47 PM
#5
Thread Starter
Frenzied Member
Re: Uploading File, Not Working!
Do I need to change the folder permissions of /tmp/?
-
Oct 11th, 2009, 05:58 PM
#6
Thread Starter
Frenzied Member
Re: Uploading File, Not Working!
With my regular code, this is being displayed:
Upload: Test Announcement.mp3
Type: audio/mpeg
Size: 398.8095703125 Kb
Temp file: /tmp/phpqWofVC
Yet, the mp3 isn't placed in the folder... I contacted tech support for my server host (godaddy) and besides saying they don't help with script related problems they told me I can change anything I want.. (which I already new..)
-
Oct 11th, 2009, 07:41 PM
#7
Re: Uploading File, Not Working!
if you're using godaddy as a host, you wouldn't have access to be able to see or modify /tmp/ anyway, so I'm not sure what you're talking about.
anyway, if your godaddy hosting account is using PHP4, you should already have a file in your root directory called php.ini. if you're using PHP5 instead, you'll need to create a file (assuming you haven't already) called php5.ini. I would suggest copying the original php.ini file in your root directory, and then naming the copy php5.ini. then, make sure the following directives are set in the file (if they aren't showing, then add them yourself:
Code:
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Whether to allow HTTP file uploads.
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = /full/path/to/your/root/dir/tmp
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
make sure you change upload_tmp_dir to the full path of a folder called "tmp" in your root directory ("/home/username/" or something -- you can find out by going into the control panel for your hosting account, probably), and make sure that the "tmp" directory exists. I'm not sure if this will work, but it might be worth a shot. change upload_max_filesize, too, if you need to (since you're uploading mp3 files).
Last edited by kows; Oct 11th, 2009 at 07:45 PM.
-
Oct 11th, 2009, 08:16 PM
#8
Re: Uploading File, Not Working!
This is an example of uploading an image try editing it to upload mp3s or whatever you want. You just need to create the database and the tables.
PHP Code:
<?php if ($_FILES['userfile']!= ""){ $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); $content = addslashes($content); fclose($fp);
if (!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $mysql_link = mysql_connect("localhost", "root","") or die ("Unable to connect to mysql server!"); mysql_select_db ("imagedb",$mysql_link) or die ("Unable to connect to image database!"); $query = "INSERT INTO images (name, size, type, content) VALUES ('$fileName','$fileSize','$fileType','$content')"; mysql_query($query) or die ('Error!, query failed.'); echo "<br />File $fileName uploaded <br />"; } else { echo "< br />No File Selected!< br />"; } ?>
Edit:
HTML Code:
<html>
<head>
<title> File Upload </title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data" name="uploadform">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" class="box" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>
Last edited by Nightwalker83; Oct 11th, 2009 at 08:19 PM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Oct 11th, 2009, 10:47 PM
#9
Thread Starter
Frenzied Member
Re: Uploading File, Not Working!
 Originally Posted by kows
if you're using godaddy as a host, you wouldn't have access to be able to see or modify /tmp/ anyway, so I'm not sure what you're talking about.
I am on a virtual deticated server, which means I have access to change any folder..
Ill check the tmp dir path, but with the max file size, I set it to 8M already.
-
Oct 12th, 2009, 09:42 AM
#10
Re: Uploading File, Not Working!
 Originally Posted by noahssite
I am on a virtual deticated server, which means I have access to change any folder..
Ill check the tmp dir path, but with the max file size, I set it to 8M already.
ah, well, the maximum file size wouldn't have actually helped, I just thought it would be a good idea to change it. anyway, let me know how it turns out.
 Originally Posted by Nightwalker83
This is an example of uploading an image try editing it to upload mp3s or whatever you want. You just need to create the database and the tables.
sometimes I'm curious if you finish reading the threads you post these in ;) he already has working code for file uploads. it's a configuration problem.
-
Oct 12th, 2009, 06:38 PM
#11
Re: Uploading File, Not Working!
 Originally Posted by kows
sometimes I'm curious if you finish reading the threads you post these in  he already has working code for file uploads. it's a configuration problem.
Ah ok! I got confused by post #3.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|