472,785 Members | 1,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,785 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 16952
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.