Posted by David T. Ashley on 10/25/07 15:17
"admyc" <admyc@hotmail.com> wrote in message
news:1193324639.891114.316160@57g2000hsv.googlegroups.com...
> Hello
>
> I am having trouble making PHP web page that uploads an image file and
> moves it to a new file name. The problem occurs when the new filename
> already exists.
>
> I am using move_uploaded_file().
>
> The fist time an image file is uploaded and moved to a new file name
> there is no problem, however if I decide to upload a different image
> file, when the script tries to move this to the same filename (which
> is what I want as I want the uploaded file to have a specific name) it
> doesn't work and a couple of warning messages are shown one saying
> 'failed to open stream: No such file or directory in...' and the other
> saying 'Unable to move '...\tmp\php42.tmp' to 'htdocs/.../images/
> newimagename.jpg' ...'
>
> I have looked at www.w3schools.com and it says 'Note: If the
> destination file already exists, it will be overwritten.' however I
> think the problem is that this is not happening?
>
> Any help very much appreciated
It isn't clear to me why you are going to www.w3schools.com for PHP
documentation when the official PHP site is www.php.net.
If you go to this page:
http://us3.php.net/manual/en/function.move-uploaded-file.php
there are two strong hints about what might be going wrong. The second one
is pasted in below. This may or may not solve your problem; but in any case
the URL above should be your starting point IMHO.
Dave.
-------------
when you get this 2 Warnings - paths are a real sample - ::
-
move_uploaded_file(/uploads/images/sample.png)
[function.move-uploaded-file]: failed to open stream: No such file or
directory in /scripts/php/system/upload-file.php on line X
-
and
-
move_uploaded_file() [function.move-uploaded-file]: Unable to move
'/tmp/somefilename' to '/uploads/images/sample.png' in
/scripts/php/system/upload-file.php on line X
-
probably the path '/uploads/images/sample.png' is incomplete, in my case the
complet path is "/home/x-user/public_html/uploads/images/sample.png"
you can use getcwd() to know the current working directory.
:)
--
David T. Ashley (dta@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
[Back to original message]
|