Jump to content

[SOLVED] Trouble uploading pictures to a site


steve m

Recommended Posts

Hello all,

 

I am have problems with uploading pictures to this site that I am working on.  I've been testing it on my local machine and it works fine.  The picture is resized and a copy of the picture is saved to the folder that I want it to be saved at.  It even save the correct url to the data base.  When I uploaded the files to this site and tried to run the scripts it doesn't work.  The picture isn't saved and even the file name of the picture isn't saved to the database.  It seems like the file name is not being passed for example... "images/" the file name of the picture is not saved.  I know wit script it works on my local machine, but not from the site where it is to be used.

 

I've tried several different things as far as how to handle the POST varibles like using $_POST[], $_REQUEST[], but I still can't to get it ti work.  Can anyone tell me what I'm doing wrong?

 

HTML Form

<form ENCTYPE="multipart/form-data" name="loadpict" action="write_upload_picts.php" method="post">
							<p>

								<label for="pict">Picture: </label>
								<input id="pict" type="file" name="picturl" />
							</p>
							<p>
								<label for="text">Caption: </label>
								<textarea id="text" name="caption" cols="10" rows="5"></textarea>
							</p>
						<input class="formbutton" type="submit" name="submit" value="Save Picture">
</form>

 

PHP Code:

<?php
	list($width,$height)=getimagesize($picturl);

		if(($width > 640) && ($height < $width))
		{					
			$newwidth=640;
			$newheight=($height/$width)*$newwidth;

			//resizeImage($width, $height, $picturl, $newwidth, $newheight);

			// Create an Image from it so we can do the resize
				$src = imagecreatefromjpeg($picturl);

			// Capture the original size of the uploaded image
				list($width,$height)=getimagesize($picturl);

				$tmp=imagecreatetruecolor($newwidth,$newheight);

			// this line actually does the image resizing, copying from the original
			// image into the $tmp image
				imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 

			// now write the resized image to disk. I have assumed that you want the
			// resized, uploaded image file to reside in the ./images subdirectory.
				$filename = "../images/". $_FILES['picturl']['name'];
				imagejpeg($tmp,$filename,100);

				imagedestroy($src);
				imagedestroy($tmp);
?>

Link to comment
Share on other sites

Why are you not using the stanard move uploaded file function for this?  Here is an example of what I'm taking about:

http://www.w3schools.com/php/php_file_upload.asp

 

Has php introduced some new way of doing this that I am not aware of?  If this is not the problem perhaps the max upload file size option in the php.ini file is set to low.

Link to comment
Share on other sites

I was using this script to resize the image if it is larger than a certain width or height.  I do see what you mean now.  So instead of using "imagejpeg($tmp,$filename,100);" use the move file upload?  I do use that if the image is under the width and height restrictions.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.