comp.lang.php
am 25.10.2007 17:03:59 von admyc
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
Thanks
AM
Re: comp.lang.php
am 25.10.2007 17:17:46 von dta
"admyc" 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)
Re: comp.lang.php
am 25.10.2007 17:54:46 von Shelly
"admyc" 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
>
> Thanks
>
> AM
When you get more than one error message, always look at the first one as
this usually the reason for the second one occurring. In this case you have
"No such file or directory in..." meaning you have incorrectly specified the
file you are moving.
Shelly
Re: comp.lang.php
am 25.10.2007 20:12:40 von admyc
On 25 Oct, 16:17, "David T. Ashley" wrote:
> "admyc" 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 atwww.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 towww.w3schools.comfor PHP
> documentation when the official PHP site iswww.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 (d...@e3ft.com)http://www.e3ft.com (Consulting Home Page)http://www.dtashley.com (Personal Home Page)http://gpl.e3ft.com (GPL Publications and Projects)
Thanks for your reply,
I could find nothing to help at your link!
The example you kindly pasted doesn't explain it because as I wrote in
my explanation of the problem, the first time a file is uploaded and
moved to the new file name there is no problem; it is only when
another file is uploaded that it encounters the problem but as it uses
exactly the same code I don't see how the path is incomplete!
What I have noticed is that if the file exists at the original
destination, as it will when a file has already been uploaded and
moved there, then the directory that the destination path is relevant
to changes from being a few levels-up from the directory the php
document is in to being relevant to the directory the php document is
in. This therefore will explain why the first time round the directory
exists but on consequent uploads when the root directory has changed
it doesn't exist.
I really don't know why it is doing this though and any pointers very
gratefully received
AM
Re: comp.lang.php
am 25.10.2007 20:44:52 von Macca
Try someting like this maybe... (untested)
//move the image
if(!is_file("$image_destination/$picture_name")){
move_uploaded_file($_FILES[$form_fieldname]
['tmp_name'],$image_destination.'/'.$_FILES[$form_fieldname]
[$picture_name]);
} else {
//An image with that name already exists so remove
it
unlink("$image_destination/$picture_name");
move_uploaded_file($_FILES[$form_fieldname]['tmp_name'],
$image_destination.'/'.$_FILES[$form_fieldname][$picture_nam e]);
}
Re: comp.lang.php
am 25.10.2007 20:44:58 von 4sak3n 0ne
On Oct 25, 11:12 am, admyc wrote:
> On 25 Oct, 16:17, "David T. Ashley" wrote:
>
>
>
> > "admyc" 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 atwww.w3schools.comand 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 towww.w3schools.comforPHP
> > documentation when the official PHP site iswww.php.net.
>
> > If you go to this page:
>
> >http://us3.php.net/manual/en/function.move-uploaded-file.ph p
>
> > 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 (d...@e3ft.com)http://www.e3ft.com (Consulting Home Page)http://www.dtashley.com (Personal Home Page)http://gpl.e3ft.com (GPL Publications and Projects)
>
> Thanks for your reply,
>
> I could find nothing to help at your link!
>
> The example you kindly pasted doesn't explain it because as I wrote in
> my explanation of the problem, the first time a file is uploaded and
> moved to the new file name there is no problem; it is only when
> another file is uploaded that it encounters the problem but as it uses
> exactly the same code I don't see how the path is incomplete!
>
> What I have noticed is that if the file exists at the original
> destination, as it will when a file has already been uploaded and
> moved there, then the directory that the destination path is relevant
> to changes from being a few levels-up from the directory the php
> document is in to being relevant to the directory the php document is
> in. This therefore will explain why the first time round the directory
> exists but on consequent uploads when the root directory has changed
> it doesn't exist.
>
> I really don't know why it is doing this though and any pointers very
> gratefully received
>
> AM
Try clearing your browser's cache. Often times browsers cache the old
image and don't bother to look at the new one. If this isn't the
problem, the only thing I can think of is to check if the file exists
(http://us3.php.net/manual/en/function.file-exists.php) and delete it
before the move (http://us3.php.net/manual/en/function.unlink.php).
Hope that helps.
Re: comp.lang.php
am 25.10.2007 20:52:00 von 4sak3n 0ne
On Oct 25, 11:12 am, admyc wrote:
> On 25 Oct, 16:17, "David T. Ashley" wrote:
>
>
>
> > "admyc" 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 atwww.w3schools.comand 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 towww.w3schools.comforPHP
> > documentation when the official PHP site iswww.php.net.
>
> > If you go to this page:
>
> >http://us3.php.net/manual/en/function.move-uploaded-file.ph p
>
> > 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 (d...@e3ft.com)http://www.e3ft.com (Consulting Home Page)http://www.dtashley.com (Personal Home Page)http://gpl.e3ft.com (GPL Publications and Projects)
>
> Thanks for your reply,
>
> I could find nothing to help at your link!
>
> The example you kindly pasted doesn't explain it because as I wrote in
> my explanation of the problem, the first time a file is uploaded and
> moved to the new file name there is no problem; it is only when
> another file is uploaded that it encounters the problem but as it uses
> exactly the same code I don't see how the path is incomplete!
>
> What I have noticed is that if the file exists at the original
> destination, as it will when a file has already been uploaded and
> moved there, then the directory that the destination path is relevant
> to changes from being a few levels-up from the directory the php
> document is in to being relevant to the directory the php document is
> in. This therefore will explain why the first time round the directory
> exists but on consequent uploads when the root directory has changed
> it doesn't exist.
>
> I really don't know why it is doing this though and any pointers very
> gratefully received
>
> AM
Clear your browser's cache, and refresh. If the image is still wrong,
then the only thing I can think of is to check if the file exists
(http://www.php.net/file_exists) and then delete the file (http://
www.php.net/unlink) before doing the rest.
Re: comp.lang.php
am 25.10.2007 23:32:58 von unknown
Post removed (X-No-Archive: yes)
Re: comp.lang.php
am 26.10.2007 02:59:46 von Courtney
admyc wrote:
> On 25 Oct, 16:17, "David T. Ashley" wrote:
>> "admyc" 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 atwww.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 towww.w3schools.comfor PHP
>> documentation when the official PHP site iswww.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 (d...@e3ft.com)http://www.e3ft.com (Consulting Home Page)http://www.dtashley.com (Personal Home Page)http://gpl.e3ft.com (GPL Publications and Projects)
>
> Thanks for your reply,
>
> I could find nothing to help at your link!
>
> The example you kindly pasted doesn't explain it because as I wrote in
> my explanation of the problem, the first time a file is uploaded and
> moved to the new file name there is no problem; it is only when
> another file is uploaded that it encounters the problem but as it uses
> exactly the same code I don't see how the path is incomplete!
>
Don't use 'move file' then, use the copy command.
i had issues using move uploaded file anyway. Copy resolved them.
Or unlink() the existing file before moving. Whichever. Unlink should be
happy with a non existent file anyway.
> What I have noticed is that if the file exists at the original
> destination, as it will when a file has already been uploaded and
> moved there, then the directory that the destination path is relevant
> to changes from being a few levels-up from the directory the php
> document is in to being relevant to the directory the php document is
> in. This therefore will explain why the first time round the directory
> exists but on consequent uploads when the root directory has changed
> it doesn't exist.
>
> I really don't know why it is doing this though and any pointers very
> gratefully received
>
> AM
>
Re: comp.lang.php
am 28.10.2007 16:35:10 von tito001945
On Oct 25, 11:03 pm, admyc wrote:
> 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 atwww.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
>
> Thanks
>
> AM
if you upload a file . you can change the file to anther name . for
example , you can give the file a new name like
=mktime()?>.jpg or =mtkime()?>.bmp .