473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

php image upload ,resize &making thumbnail

hii all
Truly telling i hav got this code from net &
i am finding error while running the code below..

code:-
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $idir = "photo/";   // Path To Images Directory
  3. $tdir = "photo/thumbs/";   // Path To Thumbnails Directory
  4. $twidth = "125";   // Maximum Width For Thumbnail Images
  5. $theight = "100";   // Maximum Height For Thumbnail Images
  6.  
  7. if (!isset($_GET['subpage'])) {   // Image Upload Form Below   ?>
  8.   <form method="post" action="addphoto.php?subpage=upload" enctype="multipart/form-data">
  9.    File:<br />
  10.   <input type="file" name="imagefile" class="form">
  11.   <br /><br />
  12.   <input name="submit" type="submit" value="Sumbit" class="form">  <input type="reset" value="Clear" class="form">
  13.   </form>
  14. <? } else  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script
  15.   $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use
  16.   if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {
  17.     $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php
  18.     $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location
  19.     if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location
  20.       print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image
  21.       $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From
  22.       $currwidth = imagesx($simg);   // Current Image Width
  23.       $currheight = imagesy($simg);   // Current Image Height
  24.       if ($currheight > $currwidth) {   // If Height Is Greater Than Width
  25.          $zoom = $twidth / $currheight;   // Length Ratio For Width
  26.          $newheight = $theight;   // Height Is Equal To Max Height
  27.          $newwidth = $currwidth * $zoom;   // Creates The New Width
  28.       } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
  29.         $zoom = $twidth / $currwidth;   // Length Ratio For Height
  30.         $newwidth = $twidth;   // Width Is Equal To Max Width
  31.         $newheight = $currheight * $zoom;   // Creates The New Height
  32.       }
  33.       $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail
  34.       imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete
  35.       $palsize = ImageColorsTotal($simg);
  36.       for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image
  37.        $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used
  38.        ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use
  39.       }
  40.       imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)
  41.       imagejpeg($dimg, "$tdir" . $url);   // Saving The Image
  42.       imagedestroy($simg);   // Destroying The Temporary Image
  43.       imagedestroy($dimg);   // Destroying The Other Temporary Image
  44.       print 'Image thumbnail created successfully.';   // Resize successful
  45.     } else {
  46.       print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed
  47.     }
  48.   } else {
  49.     print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong
  50.     print $file_ext;   // Show The Invalid File's Extention
  51.     print '.</font>';
  52.   }
  53. } ?>
  54.  
error :-
Expand|Select|Wrap|Line Numbers
  1. Warning: copy(photo/DSC00031.JPG): failed to open stream: Permission denied in /hsphere/local/home/wwwuser/home.mishra.biz/addphoto.php on line 18 ERROR: Unable to upload image.
  2.  
line 18 is $copy=....

anyone can help me i would b grateful..
Nov 21 '07 #1
7 17018
Markus
6,050 Expert 4TB
Sounds like you dont have the right file permissions set.

You need to chmod the directory to a more appropriate level!
[php]
<?php
chmod("/directory/to/chmod", 0755);
?>
[/php]

Lemme know if this helps!

Also! Remember to wrap your php code in the CODE tags.

IT helps people look through your code :)
Nov 21 '07 #2
Atli
5,058 Expert 4TB
Hi.

Please use [code] tags when posting your code examples. (See How to ask a question)

[code=php] ...PHP code goes here... [/code]

Thank you.
Nov 21 '07 #3
Sounds like you dont have the right file permissions set.

You need to chmod the directory to a more appropriate level!
[php]
<?php
chmod("/directory/to/chmod", 0755);
?>
[/php]

Lemme know if this helps!

Also! Remember to wrap your php code in the CODE tags.

IT helps people look through your code :)
i hav executed the code u said
Expand|Select|Wrap|Line Numbers
  1.       <?php
  2.       chmod("/directory/to/chmod", 0755);
  3.         ?>
  4.  
  5.  
but it gives error , i replaced 'directory' by 'photo' the folder i hav created to store uploaded photo..but still it is giving error

see the error:-

Warning: chmod(): No such file or directory in /local/home/wwwuser/home.mishra.biz/chmod.php on line 2


please tell me what else to do..
i need the solution soon..
if u can i will be obliged..
Nov 23 '07 #4
Atli
5,058 Expert 4TB
How exactly did the path you use look?

If you want to use a relative path, a path relative to the current directory, there should not be a / in front of it.

On the other hand, if you are using an absolute path, a path relative to the root directory, you should put a / in front of it.

Like:
Expand|Select|Wrap|Line Numbers
  1. # An absolute path
  2. chmod("/var/www/html/images/image.jpg", 0755);
  3.  
  4. # A relative path, assuming the current directory is /var/www/html
  5. chmod("images/image.jpg", 0755);
  6.  
Nov 23 '07 #5
Markus
6,050 Expert 4TB
It's not the image he's wanting to chmod() is it?

Am i right in thinking he would also need to chmod the php file that is executing? i.e. the uploader script aswell as the actual directory where the images would be stored? Or is that not necessary?
Nov 23 '07 #6
Atli
5,058 Expert 4TB
It's not the image he's wanting to chmod() is it?

Am i right in thinking he would also need to chmod the php file that is executing? i.e. the uploader script aswell as the actual directory where the images would be stored? Or is that not necessary?
It doesn't really matter whether it is a file or a directory. All directories in a Linux system are essentially files anyways so the chmod command works the same on both.

He would not have to chmod the PHP file that is being executed, only the file or directory he intends to change.

The user running the HTTP server only needs read and execute permission on the PHP file to be able to execute it, but it needs write permission on the file the PHP script is meant to change.
Nov 24 '07 #7
Markus
6,050 Expert 4TB
It doesn't really matter whether it is a file or a directory. All directories in a Linux system are essentially files anyways so the chmod command works the same on both.

He would not have chmod the PHP file that is being executed, only the file or directory he intends to change.

The user running the HTTP server only needs read and execute permission on the PHP file to be able to execute it, but it needs write permission on the file the PHP script is meant to change.
Oh i see.

I wonder how (s)he's getting along with it ¬_¬
Nov 24 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Paul | last post by:
Hi, I am writing an ASP site that contains images. The owner of the site wants to be able to upload images. The only problem is that the owner is not computer literate enough to be able to...
1
by: manish | last post by:
Hi, I am a fresher in the programming field i.e although I have done programming at the basic level but at professional level I am very new and I am facing many problems. These probllems are...
8
by: Chris Dewin | last post by:
Hi. I run a website for my band, and the other guys want an image gallery. I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client...
2
by: Mark R. Dawson | last post by:
Hi all, I have a directory full of images (most over 2MB in size) I was to show each image as a thumbnail on a form, however in order to create a thumbnail I have to open the complete image then...
6
by: Trint Smith | last post by:
How can I show image thumbnail?? thanks, Trint ..Net programmer trintsmith@hotmail.com *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get...
5
by: sp_mclaugh | last post by:
Hi. I've just recently switched to using CSS (rather than tables) to display collections of thumbnails. That way, depending on the user's screen resolution and browser window size, the number of...
2
by: Michiel Sikma | last post by:
Hello everybody. I'm currently involved in a site building project in which we're going to use the Google Maps API. The user will be able to browse the site by looking over a really large image,...
1
by: dodgeyb | last post by:
Hi there, Trying to allow client to upload image, thumbnail it, and save it into sql table image field. Code compiles & runs but image cannot be retrieved. any clues what I'm doing wrong pls ! ...
1
by: karanmymatrix | last post by:
Req Code For Horizontal Bar Attach To Image Thumbnail. With Every Change In Horizontal Bar ,it Scroll To New Image In Thumbnaiil !!! Plz Give Code For Same As Early As Possible!!!
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.