PDA

View Full Version : uploading with php



getartzy
08-06-2007, 02:36 PM
I have been trying for days to get my php scripts to upload a file. The script worked before on my machine but not on host monster. I changed the permissions of the folder to allow writing by every one,I changed the php.ini max size(as per the knowledge db entry.) to be greater than the filesize I am uploading, and I have searched on here(might have missed it though.) I have also been playing with my code to see If I did any thing wrong. So far I have no answers except.



Warning: move_uploaded_file(/artistsfiles/979293716_l.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/getartzy/public_html/upload.php on line 12

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpz1K3tn' to '/artistsfiles/979293716_l.jpg' in /home/getartzy/public_html/upload.php on line 12

Sorry thier was an error uploading this file! This could be due to a large file size. The current limit is 1MB
Array
(
[userfile] => Array
(
[name] => 979293716_l.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpz1K3tn
[error] => 0
[size] => 23216
)

)
Which is not a vary good answer.

I wrote the message "Sorry their was an error uploading this file! This could be due to a large file size. The current limit is 1MB" in my script to show the user a failer. But the first two messages are confusing to me and I don't don't know why I am getting them.


<?php
INCLUDE 'dbs.php';
INCLUDE 'sitelayout.php';
connect();
$frrt = "UPDATE `artist profiles` SET `port` = '1' WHERE `uid` = '".$_COOKIE['igg']."' ";
$result = mysql_query($frrt);
$frrt = "UPDATE `accounts` SET `port` = '1' WHERE `ID` = '".$_COOKIE['igg']."' ";
$result = mysql_query($frrt);
$uploaddir = '/artistsfiles/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
$hy = move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
if ($hy) {

$frrt = "SELECT `id` FROM `artist profiles` WHERE `uid` = '".$_COOKIE['igg']."' LIMIT 0, 30 ";
$result = mysql_query($frrt);
while ($tt = mysql_fetch_array($result)) {

$frrt = "INSERT INTO `portfolio` (`uid`,`filename`, `desc`, `capt`,`proid`) VALUES ('".$_COOKIE['igg']."','".$_FILES['userfile']['name']."','".$_REQUEST['descript']."','".$_REQUEST['caption']."','".$tt{'id'}."')";

$result = mysql_query($frrt);

echo "<meta http-equiv=\"Refresh\" content=\"0; URL= Artisthome.php?igg=".$_REQUEST['igg']."\">";

}

} else {
echo "Sorry thier was an error uploading this file! This could be due to a large file size. The current limit is 1MB\n";
}
print_r($_FILES);

?>

What am I doing wrong?

charlesgan
08-06-2007, 07:34 PM
you can change the 1M limit. Open the php.ini and change the

upload_max_filesize = 2M

to something bigger

getartzy
08-06-2007, 10:07 PM
[size] => 23216thats 23,216 b or 23.2kb

Why would I need any thing more than one mb?

I tried that before posting. I bumped it up to 10MB. still I get the same error. Any ideas

linFox
08-07-2007, 06:49 AM
The path you are moving the file to is incorrect. You need to add your website's root path to the front of the destination path. With the current path, PHP is trying to put the files in a folder on the root of the drive (which doesn't exist, hence the 'No such file or directory error), not the root of your website.

Change the line

$uploaddir = '/artistsfiles/';
to

$uploaddir = $_SERVER['DOCUMENT_ROOT'].'/artistsfiles/';

getartzy
08-07-2007, 03:21 PM
Yep, that was what was wrong. Thank you so much for the help. I did not even think about the file structurer being set up that way.

xtendedf
08-15-2007, 04:23 AM
[size] => 23216thats 23,216 b or 23.2kb

Why would I need any thing more than one mb?

I tried that before posting. I bumped it up to 10MB. still I get the same error. Any ideas

excuse my ignorance, but I can't seem to find the
php.ini file anywhere. i've looked everywhere??