APD Toronto
asked on
Uploading With PHP
Hello Experts,
I am trying to do an excersise for file upload from a text book, but when trying to upload with the started code, and even without changing anything I got:
Warning: getimagesize(C:\inetpub\ww wroot\phpB ook\ex_sta rts\ch23_e x1\images\ leaf.gif): failed to open stream: No such file or directory in C:\inetpub\wwwroot\phpBook \ex_starts \ch23_ex1\ image_util .php on line 34
File must be a JPEG, GIF, or PNG image.
To try to troubleshoot, I added a few echo statements, and the output is:
src =
target = C:\inetpub\wwwroot\phpBook \ex_starts \ch23_ex1\ images\lea f.gif
dir = C:\inetpub\wwwroot\phpBook \ex_starts \ch23_ex1\ images
dir = C:\inetpub\wwwroot\phpBook \ex_starts \ch23_ex1\ images\
img = C:\inetpub\wwwroot\phpBook \ex_starts \ch23_ex1\ images\lea f.gif
So, I think that the issue is because src ($source), is an empty string. I'm posting my code, and the src = $source is coming from Li.25 of index.php.
Please advise.
ch23-ex1.zip
I am trying to do an excersise for file upload from a text book, but when trying to upload with the started code, and even without changing anything I got:
Warning: getimagesize(C:\inetpub\ww
File must be a JPEG, GIF, or PNG image.
To try to troubleshoot, I added a few echo statements, and the output is:
src =
target = C:\inetpub\wwwroot\phpBook
dir = C:\inetpub\wwwroot\phpBook
dir = C:\inetpub\wwwroot\phpBook
img = C:\inetpub\wwwroot\phpBook
So, I think that the issue is because src ($source), is an empty string. I'm posting my code, and the src = $source is coming from Li.25 of index.php.
Please advise.
ch23-ex1.zip
ASKER
Hi Ray,
Running your code directly, no changes, I get:
Fatal error: Missing a temporary folder in C:\inetpub\wwwroot\upload. php on line 68
Running your code directly, no changes, I get:
Fatal error: Missing a temporary folder in C:\inetpub\wwwroot\upload.
Line 68 is a blank line in my script, so I'm fairly sure the error is not caused by that line. Any other hints you can give us about what your script is doing?
ASKER
Sorry had 2 empty lines, the error is at Li.66
This means the upload failed because the server does not have a temporary folder to stash the uploaded files until your script can get control of them and move them to permanent storage. Some useful references:
http://php.net/manual/en/features.file-upload.post-method.php
http://php.net/manual/en/features.file-upload.errors.php
http://php.net/manual/en/features.file-upload.post-method.php
http://php.net/manual/en/features.file-upload.errors.php
Files will, by default be stored in the server's default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini. The server's default directory can be changed by setting the environment variable TMPDIR in the environment in which PHP runs. Setting it using putenv() from within a PHP script will not work. This environment variable can also be used to make sure that other operations are working on uploaded files, as well.To see your settings for the temporary directory, you might try running phpinfo() and looking in the output for upload_tmp_dir. This path needs to be universally writable.
ASKER
OK, that fixed my upload directory, and your code works.
Now, to my original issue, I still get some errors, and my output is below. You'll see that Li.1 is no longer an empty string (thanks to you), but i still error out on getimagesize().
Now, to my original issue, I still get some errors, and my output is below. You'll see that Li.1 is no longer an empty string (thanks to you), but i still error out on getimagesize().
src = C:\php\upload_tmp_dir\php21E5.tmp
target = C:\inetpub\wwwroot\phpBook\ex_starts\ch23_ex1\images\leaf.gif
dir = C:\inetpub\wwwroot\phpBook\ex_starts\ch23_ex1\images
dir = C:\inetpub\wwwroot\phpBook\ex_starts\ch23_ex1\images\
img = C:\inetpub\wwwroot\phpBook\ex_starts\ch23_ex1\images\leaf.gif
Warning: getimagesize(): open_basedir restriction in effect. File('C:\inetpub\wwwroot\phpBook\ex_starts\ch23_ex1\images\leaf.gif') is not within the allowed path(s): (c:\inetpub\wwwroot;c:\php) in C:\inetpub\wwwroot\phpBook\ex_starts\ch23_ex1\image_util.php on line 34
Warning: getimagesize('C:\inetpub\wwwroot\phpBook\ex_starts\ch23_ex1\images\leaf.gif'): failed to open stream: Operation not permitted in C:\inetpub\wwwroot\phpBook\ex_starts\ch23_ex1\image_util.php on line 34
File must be a JPEG, GIF, or PNG image.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Ray, I'll have a look
Any feedback on my PEAR question
Any feedback on my PEAR question
I saw it, but I've never used Pear so I didn't feel competent to offer a response. Just curious - why use Pear? Most of the people I know stay away from it since there are newer and better technologies for most of the things it does.
ASKER
Thanks Ray, another solved question.
PEAR because it is part of the curriculum, and I feel most hosts are comfortable with it.
PEAR because it is part of the curriculum, and I feel most hosts are comfortable with it.
because it is part of the curriculum,...Ha! Yep, I understand. If there were one thing I would recommend today it would be the Laravel framework. If you truly understand the power of well-constructed PHP frameworks, you'll be over the moon when you see how this one works.
Open in new window