Page 1 of 1

odd file upload problem

Posted: Wed Jul 24, 2002 2:52 pm
by fariquzeli
I have a small script that uploads a file, I checked the root dir path and that works fine, and I have file uploads enabled in php.ini. I get 2 errors when submitting, here is the code:

Code: Select all

<?php
if (!IsSet($action)) &#123;
?>
            <form action="<?=$PHP_SELF;?>" method="post" enctype="multipart/form-data" name="fileUpload">
              <table width="100%" border="0" cellspacing="3" cellpadding="0">
                <tr> 
                  <td width="20%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Newsletter 
                    Title:</font></td>
                  <td width="80%"><input name="name" type="text" id="name"></td>
                </tr>
                <tr> 
                  <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">File 
                    Attachment:</font></td>
                  <td><input type="file" name="pdfnewsletters"></td>
                </tr>
                <tr> 
                  <td>&nbsp;</td>
                  <td>
				  <input type="hidden"name="link"value="http://www.pancorp.com/newsletter/downloads/<?php echo("$pdfnewsletters_name"); ?>">
				  <input type="hidden" name="username"value="<?php echo("$username"); ?>">
				  <input name="action" type="submit" id="action" value="Submit"> 
                    <input name="Reset" type="reset" id="Reset" value="Reset"></td>
                </tr>
              </table>
            </form>
            <?php 
&#125;
else &#123;
copy($pdfnewsletters, "/home/ttoomey/pancorp.com/newsletter/downloads/$pdfnewsletters");
unlink($pdfnewsletters);
mysql_connect($hostname, $user, $pass);
mysql_select_db("pancorp");
$sql = "INSERT INTO newsletters SET
name = '$name',
link = '$link',
username = '$username'";
$result = mysql_query($sql) or die(mysql_error);
?>
<center><br><br><br>

You have successfully submitted a new newsletter .pdf. Have a cookie.<BR><BR><BR></center>
<?php
&#125;
?>
the errors i am getting are:
Warning: Unable to create '/home/ttoomey/pancorp.com/newsletter/downloads//tmp/php12HrHf': No such file or directory in /home/ttoomey/pancorp.com/newsletter/admin/upload.php on line 54

Warning: Use of undefined constant mysql_error - assumed 'mysql_error' in /home/ttoomey/pancorp.com/newsletter/admin/upload.php on line 62
mysql_error

I read through some past topics and noticed that i had to chmod, tried that, and still had no luck. i'm using php 4.0.6. on an apache webserver. Any help is appreciated.

Posted: Wed Jul 24, 2002 2:57 pm
by fariquzeli
i have the mysql_error taken care of that was my mistake, but the upload problem i'm still having.

Posted: Wed Jul 24, 2002 2:59 pm
by RandomEngy
Hmm... haven't done any file uploading in 4.0.6, only 4.2.1. But I can tell you how to get rid of your second warning. It should be mysql_error() instead of mysql_error .

Posted: Wed Jul 24, 2002 3:01 pm
by fariquzeli
lol, looks like we posted at the same time.

Posted: Wed Jul 24, 2002 3:11 pm
by RandomEngy
Instead of your copy statement, try:

Code: Select all

$path = "" /* The relative path from where your script is running to put the file */
move_uploaded_file($HTTP_POST_FILES&#1111;'pdfnewsletters']&#1111;'tmp_name'],$path);
PHP Post method file upload management

Info on move_uploaded_file()

Posted: Mon Jul 29, 2002 3:24 pm
by fariquzeli
When you say relative path do you mean the http://www.path.to
or

/home/user/pancorp.com/site/

and do i have to change tmp_name?

Posted: Mon Jul 29, 2002 4:20 pm
by RandomEngy
I mean like if the script you are running is located in /var/www/ , and the folder where you want to put the image is in /var/www/images/ , then the relative path would be images/mypicname.jpg .

Posted: Mon Jul 29, 2002 5:25 pm
by fariquzeli
Warning: Unable to create 'downloads/': Is a directory in /home/ttoomey/pancorp.com/newsletter/admin/upload.php on line 55

Warning: Unable to move '/tmp/phpNCX8Wd' to 'downloads/' in /home/ttoomey/pancorp.com/newsletter/admin/upload.php on line 55
That is the error i get. The directory the files are being uploaded to, downloads/, is set to chmod 777 so I don't really know what the problem is, here is the code I have:

Code: Select all

$path = "downloads/";
// The relative path from where your script is running to put the file  
move_uploaded_file($HTTP_POST_FILES&#1111;'pdfnewsletters']&#1111;'tmp_name'],$path);

Posted: Tue Jul 30, 2002 9:16 am
by RandomEngy
You have to include the full name of what it's going to be as well, so

Code: Select all

$path = "downloads/".$HTTP_POST_FILES&#1111;'pdfnewsletters']&#1111;'name']; 
// The relative path from where your script is running to put the file  
move_uploaded_file($HTTP_POST_FILES&#1111;'pdfnewsletters']&#1111;'tmp_name'],$path);
If that doesn't work, try putting in the full path. On my server putting the relative path will work; maybe it won't on yours.

Posted: Tue Jul 30, 2002 12:44 pm
by fariquzeli
ahh works wonderfully, thanks a bunch!