Forum Moderators: coopster

Message Too Old, No Replies

coyping a image to a file server

         

welshbryant

3:08 am on Mar 17, 2007 (gmt 0)

10+ Year Member



Hey fellow PHPers,

I am currently trying to upload an image to my mysql file server. It seems to go through however the file is never actually saved on the server. Attached is my code and hopefully someone can catch my mistake.

<form name="form1" method = "post" enctype = "multipart/form-data">

Photographer name: <input type="text" name="authorname" size="40" /> <br />
Upload File: <input type="file" name="filename" id = "filename" size="40" /> <br />
File Type: <select name = "select">
<option value = "JPEG">JPEG</option>
<option value = "GIF">GIF</option>
<option value = "PNG">PNG</option>
<option value = "other">Other</option>
</select>
<br />
Photo Name: <input type = "text" name = "photoname" /> <br />
Photo Description: <input type = "text" name = "photodescription" />
<br />

<input type="submit" value = "submit" />
<input type="reset" value = "reset"/>

</form>

<?php
include("connect.php") ;
$path = "/images/" ;
$authname = $_POST['authorname'];
$phototype = $_POST['select'];
$photoitself = $_POST['filename'];
$photoname = $_POST['photoname'];
$photodesc = $_POST['photodescription'];

move_uploaded_file($files['filename'] ['tmp_name'],"/public_html/images/" . $_FILES['filename']['name']);
echo "stored in: " . "images/" . $_FILES['filename']['name'];

?>

the addphoto3.php is stored under the public_html folder of my web server, and there is an images folder within the public_html where i want the images to be stored. Any help is appreciated.

winglian

3:35 am on Mar 17, 2007 (gmt 0)

10+ Year Member



did you set the correct permissions for the directory you are writing to for the appropriate user? I would try chmod'ing the target directory to 0777 to test first and then whittle down the permissions from there.

dreamcatcher

7:00 am on Mar 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi welshbryant,

You may also need to change 'public_html/images/' to simply 'images/'.

dc

welshbryant

9:00 pm on Mar 17, 2007 (gmt 0)

10+ Year Member



winglian,

all the folders in my public_html have read/write/executable access for all users. I also changed the file path to just images/. i put in an die clause and got this :

Warning: move_uploaded_file(/public_html/images/doggy.jpg): failed to open stream: No such file or directory in /home/welsh/public_html/addphoto3.php on line 55

Warning: move_uploaded_file(): Unable to move '/tmp/phpn64U28' to '/public_html/images/doggy.jpg' in /home/welsh/public_html/addphoto3.php on line 55
Error: 0

for the code:

include("connect.php") ;
$path = "/images/" ;
$authname = $_POST['authorname'];
$phototype = $_POST['select'];
$photoitself = $_POST['filename'];
$photoname = $_POST['photoname'];
$photodesc = $_POST['photodescription'];

if (move_uploaded_file($_FILES['filename']['tmp_name'],"images/" . $_FILES['filename']['name'])) {
echo 'Image uploaded!';
} else {
echo 'Error: '.$_FILES['filename']['error'];
}

welshbryant

9:08 pm on Mar 17, 2007 (gmt 0)

10+ Year Member



my mistake, when i took out the public_html from the code it said image uploaded successfully however it was the php file (addphoto3.php) that was copied not the image itself. Any ideas on how to fix it so the image not the php file is uploaded?

cameraman

9:22 pm on Mar 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried
print_r($_FILES);

to make sure you're getting what you think you're getting?

dreamcatcher

9:48 pm on Mar 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, use the is_uploaded_file [uk2.php.net] function to check that the temp file has been uploaded before attempting to move/rename it. The file_exists [uk2.php.net] function is also useful to see if the image actually has been uploaded.

dc

winglian

9:54 pm on Mar 17, 2007 (gmt 0)

10+ Year Member



have you tried?

move_uploaded_file($files['filename'] ['tmp_name'],"/home/welsh/public_html/images/" . $_FILES['filename']['name']);