Jump to content


Photo

Why won't the images upload with this script?


  • Please log in to reply
6 replies to this topic

#1 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 24 August 2006 - 05:24 AM

This code should upload a picture file to the designated folder. But.. it's not. NO pic is getting uploaded even though it provides a confirmation and no errors.

<html>
<head>
<title>Test Upload Form</title>
</head>
<body>
<?php 
//image upload test
$file_dir = "/home2/wwwplat/public_html/images/";
$file_url = "http://www.plateauprofessionals.com/images";

if (isset($image))
	{
	  print "<center>Image path: $image<br>\n";
	  print "<center>Image name: $image_name<br>\n";
	  print "<center>Image size: $image_size bytes<br>\n";
	  print "<center>Image type: $image_type<p>\n\n";
	  if ($image_type == "image/gif" )
	  {
	copy ($image, "$image_dir/$image_name") or die("Could not copy");
	print "<img src=\"$file_url/$image_name\"><p>\n\n";
	}
	}
 ?>
<form action="<?print $PHP_SELF?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="file" accept=".jpg" size="20" name="image" title="Image Upload" /><br>
<input type="submit" value="Submit">
</form>

I've validated this code by comparing it to some code in a Learn PHP book. Anyone see why it doesn't work?

#2 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 24 August 2006 - 06:30 AM

Thanks for the post and the code suggestion. Unfortunately it just displays the submit button. No form field shows.

#3 ForumGuy

ForumGuy
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 24 August 2006 - 01:28 PM

http://www.phpfreaks...c,104755.0.html

try the code in this thread it works fine for me to upload pic  ;)

just change the relevant variables and your away ;D
is it me or is it it....?

#4 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 24 August 2006 - 04:38 PM

It appears as though that code wasn't working and you were seeking help with it. Does it work?

What i'm actually trying to do is create a upload a pic, create a thumbnail that uploads at the same time, and import data into the mysql database pertaining to all the form fields and the pic references.

#5 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 24 August 2006 - 05:53 PM

This works for me.
<?php
//image upload test
$file_dir = "/home2/wwwplat/public_html/images/";
$file_url = "http://www.plateauprofessionals.com/images";

if (isset($_POST['submit']))
	{
$image_name = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_type = $_FILES['image']['type'];
$uploadfile = $file_dir.basename($image_name);
if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Possible file upload attack!\n";
}
	  print "<center>Image path: $file_dir<br>\n";
	  print "<center>Image name: $image_name<br>\n";
	  print "<center>Image size: $image_size bytes<br>\n";
	  print "<center>Image type: $image_type<p><br>\n\n";
      print "<img src=\"$file_url/$image_name\"><p>\n\n";
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="file" accept=".jpg" size="20" name="image" title="Image Upload" /><br>
<input type="submit" name=submit value="Submit">
</form>

</body>

</html>

Ray

#6 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 24 August 2006 - 07:19 PM

Thanks Ray. Actually this script was a test to see if there was a problem with uploading images to my server since i've been working on another script that for some reason just won't upload the image and create the thumbnail.

See this thread: http://www.phpfreaks...,104388.45.html

I'm creating a member profile page and a member's list/summary page. The profile will contain the full image and the summary page will have a thumbnail. I'm looking for code to parse the data for the profile entry form which also has a file upload field. The goal is to upload the original image and also create a thumbnail at the same time. The reference for each is entered into the mysql database so I can then summon them up in the profile display pages.

Any ideas?

#7 ForumGuy

ForumGuy
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 31 August 2006 - 11:18 AM

yeah my code works, if you read the post ::)

you would find the problem i have is with large file uploads, the php.ini and so on.
is it me or is it it....?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users