PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Problems uploading images with script
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Problems uploading images with script

Réponse
 
LinkBack Outils de la discussion
Vieux 25/03/2008, 13h01   #1
bizt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Problems uploading images with script

Hi,

Im having trouble with my script in the sense that it doesnt appear to
be able to access files uploaded to the temporary folder on the
server. Below is the script that I am using:

<?php

if(isset($_REQUEST['submit_add'])) {

$imgPath = $_FILES['image']['tmp_name']; // the location of the temp
file

// diplay tmp file
print_r($_FILES); echo '<br />';

// does file exists
echo (file_exists($imgPath)) ? 'File exists' : 'File does not
exist'; echo '<br />';

$arDims = getimagesize($imgPath); // function to get image
dimensions etc
print_r($arDims);

}

?><html>
<head>
</head>
<body>
<form method="post" action="test_images.php" enctype="multipart/form-
data">
<input type="file" name="image" />
<input type="submit" name="submit_add" value="Add" />
</form>

</body>
</html>



It is able to provide the location of the uploaded file from the
$_FILES array:

Array (
[image] => Array (
[name] => At the Arch.jpg
[type] => image/pjpeg
[tmp_name] => /var/tmp/phpaHKMQl
[error] => 0
[size] => 281761
)
)

.... but when I even just do a file_exists on it (/var/tmp/phpaHKMQl ..
is this a lunux path?) returns false. This may be the reason that my
getimagesize() isnt working too.

Can anyone suggest what the problem may be? Is it my script or shoud I
speak with the server guys? Ive tried this on my WAMP setup as well as
another hosting account (possibly Windows) but its only this server
which its not working. Any ideas?

Cheers

Burnsy
  Réponse avec citation
Vieux 25/03/2008, 18h01   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problems uploading images with script

bizt wrote:
> Hi,
>
> Im having trouble with my script in the sense that it doesnt appear to
> be able to access files uploaded to the temporary folder on the
> server. Below is the script that I am using:
>
> <?php
>
> if(isset($_REQUEST['submit_add'])) {
>
> $imgPath = $_FILES['image']['tmp_name']; // the location of the temp
> file
>
> // diplay tmp file
> print_r($_FILES); echo '<br />';
>
> // does file exists
> echo (file_exists($imgPath)) ? 'File exists' : 'File does not
> exist'; echo '<br />';
>
> $arDims = getimagesize($imgPath); // function to get image
> dimensions etc
> print_r($arDims);
>
> }
>
> ?><html>
> <head>
> </head>
> <body>
> <form method="post" action="test_images.php" enctype="multipart/form-
> data">
> <input type="file" name="image" />
> <input type="submit" name="submit_add" value="Add" />
> </form>
>
> </body>
> </html>
>
>
>
> It is able to provide the location of the uploaded file from the
> $_FILES array:
>
> Array (
> [image] => Array (
> [name] => At the Arch.jpg
> [type] => image/pjpeg
> [tmp_name] => /var/tmp/phpaHKMQl
> [error] => 0
> [size] => 281761
> )
> )
>
> ... but when I even just do a file_exists on it (/var/tmp/phpaHKMQl ..
> is this a lunux path?) returns false. This may be the reason that my
> getimagesize() isnt working too.
>
> Can anyone suggest what the problem may be? Is it my script or shoud I
> speak with the server guys? Ive tried this on my WAMP setup as well as
> another hosting account (possibly Windows) but its only this server
> which its not working. Any ideas?
>
> Cheers
>
> Burnsy
>


I've seen this before - the file may or may not actually exist in the
tmp folder. But even if file_exists() fails, it seems
move_uploaded_file() still works.

Try moving it to your own directory then check it out. If it isn't what
you expect, delete it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 25/03/2008, 18h18   #3
bizt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problems uploading images with script

> I've seen this before - the file may or may not actually exist in the
> tmp folder. But even if file_exists() fails, it seems
> move_uploaded_file() still works.
>
> Try moving it to your own directory then check it out. If it isn't what
> you expect, delete it.


Hi, ive tried moving it using move_uploaded_file() but it still isnt
working. Below is the code im using:

if(isset($_REQUEST['submit_add'])) {

$srcPath = $_FILES['image']['tmp_name'];
$dstPath = $_SERVER['DOCUMENT_ROOT'].'/_testing/newfile.jpg';

if(move_uploaded_file($srcPath, $dstPath)) {
echo 'WHOO HOO!!!';
} else {
echo 'NNNO!';
}

}

Ive spoken with the guy who manages the servers (unfortunetely off
work today) and he mentioned something that there may be differences
between PHP4 and PHP5 for doing this sort of thing. Is that true?

Cheers

Burnsy

  Réponse avec citation
Vieux 25/03/2008, 19h46   #4
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problems uploading images with script

bizt wrote:
>> I've seen this before - the file may or may not actually exist in the
>> tmp folder. But even if file_exists() fails, it seems
>> move_uploaded_file() still works.
>>
>> Try moving it to your own directory then check it out. If it isn't what
>> you expect, delete it.

>
> Hi, ive tried moving it using move_uploaded_file() but it still isnt
> working. Below is the code im using:
>
> if(isset($_REQUEST['submit_add'])) {
>
> $srcPath = $_FILES['image']['tmp_name'];
> $dstPath = $_SERVER['DOCUMENT_ROOT'].'/_testing/newfile.jpg';
>
> if(move_uploaded_file($srcPath, $dstPath)) {
> echo 'WHOO HOO!!!';
> } else {
> echo 'NNNO!';
> }
>
> }
>
> Ive spoken with the guy who manages the servers (unfortunetely off
> work today) and he mentioned something that there may be differences
> between PHP4 and PHP5 for doing this sort of thing. Is that true?
>
> Cheers
>
> Burnsy
>
>


No, there shouldn't be differences between PHP4 and PHP5 in this area.
Does the webserver's userid have read and write access to both directories?

Do you have all errors enabled (error_reporting = E_ALL) and are
displaying errors (display_errors=on) in your php.ini file?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h57.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16751 seconds with 12 queries