[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 12-17-2005, 07:36 AM   #1 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


PHP file uploading

Hey, sorry to bother you guys. I'm trying to use PHP to upload music to my server. (it's currently set to image files because I have no audio files on my laptop and I need to test the script). However, I keep getting the error whenever I submit the form. It stores the data in the database but doesnt store the file on the server. And since adding the enctype to the form, all the $_POST variables are empty. $NP and reputation for anyone who can solve this problem or suggest a script which will enable me to upload a music file with another field for the title of the file.

PHP Code:
<?
session_start
();
if (!isset(
$_SESSION['logged_in'])) {
echo
'<script>alert("You must be logged in to view this page.");</script>';
                echo
'<script>history.back(1);</script>';
                exit;
                }
include(
"config.php");
include(
"includes/userinfo.php");
if (
$artist == "") {
echo
"<p>You must be registered as an artist to view this page.</p> <p><a href='index.php'>Return</a></p>"; }

        
$pagetitle = "Upload a file";

if (
$_POST['submit'])
{
$file=addslashes($_POST['userfile']);
$title=addslashes($_POST['title']);

if ( empty(
$file) || empty($title) )
{

echo
'<script>alert("One or more fields were left empty, please try again.");</script>';
echo
'<script>history.back(1);</script>';
exit;

}





$query = "INSERT INTO files (id, title, file, artist, submit) VALUES
('', '$title', '$file', '$artist', '"
. $_SESSION['logged_in'] . "')";

$results = mysql_query($query);
echo
mysql_error();


################################################

$path = "uploads/";
$max_size = 200000;


if (
is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {}

if (
$HTTP_POST_FILES['userfile']['size']>$max_size) { echo "The file is too big<br>\n"; exit; }
if ((
$HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {}

if (
file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists<br>\n"; exit; }

$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);

################################################




if ($results && $res)
{
include(
"head.php");
echo
"<h1>Success</h1><p>The file was successfully uploaded.</p><p><a href='artistarea.php'>Return</a>";
include(
"foot.php");
}
else
{
include(
"head.php");
echo
"<h1>Error</h1><p>There was an error uploading the file, please try again or <a href='contact.php'>contact</a> the administrator.</p>";
include(
"foot.php");
}

mysql_close();
}

else
{
include(
"head.php");
echo
"
<h1>Upload a song/video</h1>
<form  method='post' action='upload.php'>
<table width='447' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td height='44'>File</td>
    <td><input type='file' name='userfile' class='inputbox'></td>
  </tr>
  <tr>
    <td height='48'>Title of song/video </td>
    <td><input type='text' name='title' class='inputbox'></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type='submit' name='submit' value='Submit'></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>


</form>

"
;
include(
"foot.php");
}
?>
Is the script at the moment

Thanks in advance.
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets
miseria is offline  
Old 12-17-2005, 11:42 AM   #2 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
what version of php are you using?
what error message do you get?
what is the chmod value of the folder in which you are moving the files too?
Have you ensured the tmp folder has the correct permissions ans is setup correctly in php?
Peter is offline  
Old 12-18-2005, 02:00 AM   #3 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


Quote:
Originally Posted by filth
what version of php are you using?
what error message do you get?
what is the chmod value of the folder in which you are moving the files too?
Have you ensured the tmp folder has the correct permissions ans is setup correctly in php?
PHP Version 4.3.11

Error is the one in the PHP script - "There was an error uploading the file, please try again or contact the administrator."

CHMOD - 0777

how do I check the temp folder?



Thanks filth.
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets
miseria is offline  
Old 12-18-2005, 06:02 AM   #4 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
in versions above 4.1 you should be using $_FILES instead of $HTTP_POST_FILES

try making path an absolute path on your server instead of relative to the script.

Also in the query:-

$query = "INSERT INTO files (id, title, file, artist, submit) VALUES
('', '$title', '$file', '$artist', '" . $_SESSION['logged_in'] . "')";

what are you trying to do? Are you actually trying to upload the file into the database or the name because that is not how you would go about inserting the name.

It would also be a better idea to insert the details into the database after the file has been moved, there is more potential to go wrong with copying the file than there is uploading data to the database.

Another note, have you checked the value of register globals as I have noticed you are using addslashes(). If register globals is turned on you could be causing problems with the script you should check the value of register globals THEn decide on how to treat the data.
Peter is offline  
Old 12-18-2005, 06:09 AM   #5 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


Quote:
Originally Posted by filth
in versions above 4.1 you should be using $_FILES instead of $HTTP_POST_FILES

try making path an absolute path on your server instead of relative to the script.

Also in the query:-

$query = "INSERT INTO files (id, title, file, artist, submit) VALUES
('', '$title', '$file', '$artist', '" . $_SESSION['logged_in'] . "')";

what are you trying to do? Are you actually trying to upload the file into the database or the name because that is not how you would go about inserting the name.
Well I've only just learnt PHP so I probably seem very stupid towards all this. The 'INSERT' statement just basically stores the details of the file and this works exactly how I want it to. The $_SESSION['logged_in'] is the username which the user logged in with so that i know who submitted the file.

I'll try using $_FILES like you said.

Thanks

EDIT: Actually on second thoughts - my max upload limit is 2mb so that's kinda destroyed my idea of music downloads. Thanks anyway filth
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets

Last edited by miseria; 12-18-2005 at 06:14 AM.
miseria is offline  
Old 12-18-2005, 06:23 AM   #6 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Depending on your host you may be able to increase that using htaccess
Peter is offline  
Old 12-18-2005, 12:18 PM   #7 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Quote:
Originally Posted by filth
Depending on your host you may be able to increase that using htaccess
Or...
PHP Code:
<?php

ini_set
('upload_max_filesize', '2M');

?>
2M(megabytes) is the default. Just change to whatever you need it to be. After script execution, it will be restored to the default value.
__________________
Eric is offline  
Old 12-18-2005, 12:25 PM   #8 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
will setting it in the script have any affect??

Although some directives like this can be set per script they do not work. For example register_globals, changing this in the script has no affect as what the server does has already taken place by the time the script has run, I beleive it may be the same for upload_max_filesize.
Peter is offline  
Old 12-18-2005, 12:25 PM   #9 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Also, you may have to change the post_max_size and/or memory_limit. They default to 8M.
PHP Code:
<?php

ini_set
('memory_limi', '8M');
ini_set('post_max_size', '8M');

?>
Plus....lol....max_execution_time which defaults to 30 seconds
PHP Code:
<?php

ini_set
('max_execution_time', '30');

?>
Most can be set at runtime..
__________________
Eric is offline  
Old 12-18-2005, 12:41 PM   #10 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
just had a look at http://uk.php.net/manual/en/ini.php#ini.list and upload_max_filesize can only be changed in php.ini, .htaccess or httpd.conf.

The same goes for post_max_size
Peter is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
****HUGE List of FREE File/Image/Video Hosts!**** thetzfreak Free Resources 31 02-12-2006 06:06 AM
Great Scripts for Sale With Resale Rights! Zeeble Scripts For Sale 20 01-04-2006 01:39 AM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 09:09 AM
Tutorial: How to Install Apache2 MySQL and PHP on Windows deadserious Webmaster Tutorials 35 09-21-2005 09:46 PM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 09:12 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85