Page 1 of 1

Image Uploading Problem

Posted: Fri Jul 06, 2007 2:47 pm
by haseebmaqsood
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi

 i am trying to upload an image to the folder know as images which is located at [b]C:\xampp\htdocs\AdminPanel\images[/b]

Here is a Code Through which I am Trying to do it.What type of mistake i am commiting Lots of Warrning are occuring in this process and the image does not get uploaded at desire location

Code: Select all

<?php

// Get the details of "imagefile"
$filename = $_FILES['imagefile']['name'];
$temporary_name = $_FILES['imagefile']['tmp_name'];
$mimetype = $_FILES['imagefile']['type'];
$filesize = $_FILES['imagefile']['size'];

//Open the image using the imagecreatefrom..() command based on the MIME type.
switch($mimetype) {
    case "image/jpg":
    case "image/jpeg":
        $i = imagecreatefromjpeg($temporary_name);
        break;
    case "image/gif":
        $i = imagecreatefromgif($temporary_name);
        break;
    case "image/png":
        $i = imagecreatefrompng($temporary_name);
        break;
}

//Delete the uploaded file
unlink($temporary_name);

//Save a copy of the original
imagejpeg($i,"images/Uploadfile.jpg",80);

//Specify the size of the thumbnail
$dest_x = 150;
$dest_y = 150;

//Is the original bigger than the thumbnail dimensions?
if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
    //Is the width of the original bigger than the height?
    if (imagesx($i) >= imagesy($i)) {
        $thumb_x = $dest_x;
        $thumb_y = imagesy($i)*($dest_x/imagesx($i));
    } else {
        $thumb_x = imagesx($i)*($dest_y/imagesy($i));
        $thumb_y = $dest_y;
    }
} else {
    //Using the original dimensions
    $thumb_x = imagesx($i);
    $thumb_y = imagesy($i);
}

//Generate a new image at the size of the thumbnail
$thumb = imagecreatetruecolor($thumb_x,$thumb_y);

//Copy the original image data to it using resampling
imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));

//Save the thumbnail
imagejpeg($thumb, "images/thumbnail.jpg", 80);

?>
<html>
<head>
<title>Uploading Image</title>
</head>

<body>
<form action="index.php" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="200000">";
    <input type="file" name="imagefile">
    <input type="submit" name="upload" value="Upload Image">
</form>
</body>
</html>

Warnings


Warning: unlink() [function.unlink]: Permission denied in C:\xampp\htdocs\AdminPanel\imageUpload.php on line 24

Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\xampp\htdocs\AdminPanel\imageUpload.php on line 27

Warning: imagesx(): supplied argument is not a valid Image resource in C:\xampp\htdocs\AdminPanel\imageUpload.php on line 34

Warning: imagesy(): supplied argument is not a valid Image resource in C:\xampp\htdocs\AdminPanel\imageUpload.php on line 34

Warning: imagesx(): supplied argument is not a valid Image resource in C:\xampp\htdocs\AdminPanel\imageUpload.php on line 45

Warning: imagesy(): supplied argument is not a valid Image resource in C:\xampp\htdocs\AdminPanel\imageUpload.php on line 46

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\xampp\htdocs\AdminPanel\imageUpload.php on line 50

Warning: imagesx(): supplied argument is not a valid Image resource in C:\xampp\htdocs\AdminPanel\imageUpload.php on line 53

Warning: imagesy(): supplied argument is not a valid Image resource in C:\xampp\htdocs\AdminPanel\imageUpload.php on line 53

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\xampp\htdocs\AdminPanel\imageUpload.php on line 53

Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\xampp\htdocs\AdminPanel\imageUpload.php on line 56
";


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Jul 06, 2007 3:19 pm
by superdezign
It's telling you everything that went wrong, and exactly where.

From the sound of it, the file hasn't even been stored locally, which is usually the result of never uploading a file. You don't check if the file's been uploaded yet, if it exists, if the image resource was created.. nothing. Your code assumes nothing will go wrong.

Yet, lo and behold...

You need to add conditionals. Lots of them.

Thanks

Posted: Mon Jul 09, 2007 2:02 am
by haseebmaqsood
Thanks


But i want more elaboration of it.I did not able to sort out what and where i am comiting mistake.Kindly elaborate little more


[s]Plz[/s] please
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.

Re: Thanks

Posted: Mon Jul 09, 2007 6:21 am
by superdezign
If the file hasn't been uploaded, don't run any code.
If the file is an invalid type, don't upload the file.
If the upload has an error, don't move the file.
If the file couldn't be converted to an image, don't try to manipulate it.
If the upload couldn't be moved, don't save it.

Everything that could go wrong will go wrong. You need a little something called the "if" statement, and you need a lot of it.

Image Uploading Problem

Posted: Mon Jul 09, 2007 8:20 am
by haseebmaqsood
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I used the if Condition On Simple Generic Code to make it Functional .The Path of image folder is such as 
[b]C:\xampp\htdocs\AdminPanel\images[/b]
I Think I am not provide the path in write way.My Objective is Just to upload the image on the desire folder that is IMAGES

Code: Select all

if(isset( $Submit ))
{
//If the Submitbutton was pressed do:

if ($_FILES['imagefile']['type'] == "image/gif")
{
echo "adminpanel/images/".$_FILES['imagefile']['name'];
copy ($_FILES['imagefile']['tmp_name'], "adminpanel/images/".$_FILES['imagefile']['name']) 
or die ("Could not copy");  
 echo ""; 
        echo "Name: ".$_FILES['imagefile']['name'].""; 
        echo "Size: ".$_FILES['imagefile']['size'].""; 
        echo "Type: ".$_FILES['imagefile']['type'].""; 
        echo "Copy Done...."; 
       }       
else {
            echo "<br><br>";
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
        }
} 
?> 





<html>
<head>
<title>Untitled Document</title>
</head>

<body>
		<form name="form1" method="post" action="Uimage.php" enctype="multipart/form-data">
		<input type="file" name="imagefile">
		<br>
		<input type="submit" name="Submit" value="Submit">
		</form>
</body>

</html>
 
<?
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:

if ($_FILES['imagefile']['type'] == "image/gif")
{
echo "adminpanel/images/".$_FILES['imagefile']['name'];
copy ($_FILES['imagefile']['tmp_name'], "adminpanel/images/".$_FILES['imagefile']['name']) 
or die ("Could not copy");  
 echo ""; 
        echo "Name: ".$_FILES['imagefile']['name'].""; 
        echo "Size: ".$_FILES['imagefile']['size'].""; 
        echo "Type: ".$_FILES['imagefile']['type'].""; 
        echo "Copy Done...."; 
       }       
else {
            echo "<br><br>";
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
        }
} 
?> 





<html>
<head>
<title>Untitled Document</title>
</head>

<body>
		<form name="form1" method="post" action="Uimage.php" enctype="multipart/form-data">
		<input type="file" name="imagefile">
		<br>
		<input type="submit" name="Submit" value="Submit">
		</form>
</body>

</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Jul 09, 2007 8:40 am
by superdezign
... You lost me.

Also, don't check for the submit button to be pressed. A form can be submitted without the button being sent.