470,833 Members | 1,327 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Strange file upload behavior

I was having permission problems, so I'm using a test file to make
sure uploading works.

upload.php successfully uploads a file to the images/bookcovers dir:

<html>
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="userfile">
<input type="submit" value="submit">
<input type="text" name="eh" value='meh&lt;'>
</form>

<?php
$source = $_FILES['userfile']['tmp_name'];
$dest = 'images/bookcovers/' . $_FILES['userfile']['name'];
if ( ($source != 'none') && ($source != '' )) {
move_uploaded_file( $source, $dest );
}
?>

</html>
Now, I use the same code in another php file. The file is in the same
dir as the file above, and has the same permissions. The pertinent
code is:

$source = $_FILES['small_image']['tmp_name'];
if ( ($source != 'none') && ($source != '' )) {
$dest = explode(".", $_FILES['small_image']['name']);
$dest = './images/bookcovers/' . $isbn . "_small." . $dest[1];
move_uploaded_file( $source, $dest );
$smallimg = 1;
chmod($dest,0644);
}

When I try to upload a file using the second php script, I get
permission errors:

Warning: move_uploaded_file(./images/bookcovers/0679728759_small.jpg):
failed to open stream: No such file or directory in
/home/chucknet/public_html/bookclub/addBook.php on line 120

Warning: move_uploaded_file(): Unable to move '/tmp/phpw93I5U' to
'./images/bookcovers/0679728759_small.jpg' in
/home/chucknet/public_html/bookclub/addBook.php on line 120
I'm really at a loss as to what could be causing this. Both scripts
have the same permissions and the same owner. Anyone have any
suggestions?
Jul 17 '05 #1
1 1815
Kareem Badr wrote:
I was having permission problems, so I'm using a test file to make
sure uploading works.

upload.php successfully uploads a file to the images/bookcovers dir:

snip
$dest = 'images/bookcovers/' . $_FILES['userfile']['name']; Now, I use the same code in another php file. The file is in the same
dir as the file above, and has the same permissions. The pertinent
code is:
snip
$dest = './images/bookcovers/' . $isbn . "_small." . $dest[1];
Just a hunch, depending on the server and paths, an if include is used
etc;
Try changing the latter (not working) one to the same format as the
first:

$dest = 'images/bookcovers/' . $isbn . "_small." . $dest[1];
I'm really at a loss as to what could be causing this. Both scripts
have the same permissions and the same owner. Anyone have any
suggestions?


HTH

--
Suni

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Courtney L. | last post: by
6 posts views Thread by Paul | last post: by
6 posts views Thread by Vic Spainhower | last post: by
2 posts views Thread by Mike Kober | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.