php help

Soldato
Joined
3 Jun 2008
Posts
5,060
I am trying to get an image uploading script to work. I get the following error when I try to use it to upload a file.



PHP Error Message

Warning: move_uploaded_file(/home/a2359472/public_html/pics/userpics) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/a2359472/public_html/test/index.php on line 46


PHP Error Message

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpxkAqBx' to '/home/a2359472/public_html/pics/userpics' in /home/a2359472/public_html/test/index.php on line 46

Any help is greatly appreciated.
 
Im a complete noob at this so I dont really know what you mean by "Try using if file exists to check."

Could you please clarify?

Cheers.
 
<?php
if ($_REQUEST[completed] == 1) {
$newname = uniqid("whc").".jpg";
move_uploaded_file($_FILES['mailfile']['tmp_name'],
"/home/a2359472/public_html/pics/userpics");
} ?>
<html>
<head><title>Upload page</title></head>
<body><h1>Image Uploader</h1>
<?php if ($_REQUEST[completed] != 1) { ?>
<b>Please upload an image</b><br>
<form enctype=multipart/form-data method=post>
<input type=hidden name=MAX_FILE_SIZE value=1500000>
<input type=hidden name=completed value=1>
Choose file to send: <input type=file name=mailfile> and
<input type=submit></form>
<?php } else { ?>
<b>Thanks, your picture will be on the site shortly</b>
<?php } ?>
<hr>
Copyright, etc
</body></html>

Cheers guys
 
When you move the file, I think you need to give the moved file a name. At the moment, I think you're just specifying the path to the directory. I haven't tried it, but I'd say that you'd probably need something like:

<?php
if ($_REQUEST[completed] == 1) {
$newname = uniqid("whc").".jpg";
move_uploaded_file($_FILES['mailfile']['tmp_name'],
"/home/a2359472/public_html/pics/userpics/$newname");
} ?>
 
Got a little further with that, before the error was on the same page but now i get this error on a separate page

PHP Error Message

Parse error: syntax error, unexpected '"' in /home/a2359472/public_html/test/index.php on line 46
 
I've just tested it, and yes, that does work for me. You need to make sure that you've got the right permissions to move the file too. chmod the directory to 755 if you're on a Linux server.
 
<?php
if ($_REQUEST[completed] == 1) {
$newname = uniqid("whc").".jpg";
move_uploaded_file($_FILES['mailfile']['tmp_name'],
"/var/www/development/tests/upload_test/$newname");
} ?>
<html>
<head><title>Upload page</title></head>
<body><h1>Image Uploader</h1>
<?php if ($_REQUEST[completed] != 1) { ?>
<b>Please upload an image</b><br>
<form enctype=multipart/form-data method=post>
<input type=hidden name=MAX_FILE_SIZE value=1500000>
<input type=hidden name=completed value=1>
Choose file to send: <input type=file name=mailfile> and
<input type=submit></form>
<?php } else { ?>
<b>Thanks, your picture will be on the site shortly</b>
<?php } ?>
<hr>
Copyright, etc
</body></html>

This works for me on PHP 5.2 on Debian, with the upload_test directory set to chmod 755.
 
Back
Top Bottom