Jump to content

[SOLVED] uploading image script errors .. help


drkshenronx

Recommended Posts

I keep getting this error when i try to upload the files onto my server

 

 

Warning: move_uploaded_file(images) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\wamp\www\freemmorpg\check_image.php on line 17

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'c:/wamp/tmp\php18A.tmp' to 'images' in C:\wamp\www\freemmorpg\check_image.php on line 17

 

 

This is the html form to submit the image

 

<html>
<head>
<title>Add A Screenshot</title>
</head>

<body>

<form name="upload" method ="post" action="check_image.php" enctype="multipart/form-data">

<table cellpadding="5">
<tr>
<td>Screenshot Caption <br>
<em> Example: big man, ghost pilot </em></td>

<td><input name="image_caption" type="text" id="image_caption" size="15" maxlength="255"></td>
</tr>

<td>Username<br>
<em> Example: joe123,, marty_marshin </em></td>

<td><input name="image_username" type="text" id="image_username" size="15" maxlength="255"></td>
</tr>

<td>Upload Image <br> </td>

<td><input name="image_filename" type="file" id="image_filename"></td>
</tr>
</table>

<em> Acceptable image formats include: GIF, JPG/JPEG, and PNG. </em>

<p align="center"><input type="Submit" value="Submit">  
<input type="reset" name="Submit2" value="Clear Form">
</p>
</form>


</body>
</html>

 

 

This is the script to check the image (check_image.php)

 


<?php

$con = mysql_connect('localhost', 'forums', 'password')
or die ("could not connect:" . mysql_error());
mysql_select_db("screenshots", $con)
or die (mysql_error());

$image_caption = $_POST['image_caption'];
$image_username = $_POST['image_username'];
$image_tempname = $_POST['image_filename'];
$today = date("Y-m-d");


$ImageDir = "images";
$ImageName = $ImageDir . $image_tempname;

if (move_uploaded_file($_FILES['image_filename']['tmp_name'],$ImageName)) {

	list($width, $height, $type, $attr) = getimagesize($ImageName);

switch ($type) {
	case 1:
      $ext = ".gif";
      break;
    case 2:
      $ext = ".jpg";
      break;
    case 3:
      $ext = ".png";
      break;
    default:
      echo "Sorry, but the file you are trying to upload is not a valid Image <br>";
      
     } 
      // insert the image into the table
      
      $insert = "INSERT INTO images
        (image_caption, image_username, image_date)
        VALUES
        ('$image_caption', '$image_username', '$today')";
      $insertresults = mysql_query($insert)
        or die(mysql_error());
        
      $lastpicid = mysql_insert_id();
      
      $newfilename = $ImageDir . $lastpicid . $ext;
      
      rename($ImageName, $newfilename);
      }
?>

 

Please help!!

Link to comment
Share on other sites

It depends if the folder is on a server or not. If its on a server, cPanel or Direct Admin should have a little box after all the files that says "Chmod:" then a box. Put the 777 in that box, and select the folder you want too apply the setting too, and click, OK, or something. If not, and you're using Xamp, or Wamp, then it should do it automatically for you..it did with me.

Link to comment
Share on other sites

Umm guys ... by the way chmod is only a linux command isnt it ??? so isnt it useless on a windows box .... so i think fallen fighter was right i should be able to do it regardless because all windows files and folders are set to writable when you create them. Anyone else have any ideas ???

Link to comment
Share on other sites

<td>Upload Image <br> </td>

<td><input name="image_filename" type="file" id="image_filename"></td>
</tr>
</table>

<em> Acceptable image formats include: GIF, JPG/JPEG, and PNG. </em>

<p align="center"><input type="Submit" value="Submit">  
<input type="reset" name="Submit2" value="Clear Form">

Link to comment
Share on other sites

This was the problem .. i figured it out

 

$ImageDir = "images/screenshots";
$ImageName = $ImageDir . $image_tempname;

 

I never declared the filename afterward the screenshots directory. Because of $ImageName = $ImageDir . $image_tempname;  I am supposed to supply the name to name all of my images. :P silly me .. that was my bad ... everything else was fine though. Thanks for looking!!

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.