Quantcast

Maximum PC

It is currently Wed Apr 23, 2014 10:24 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Image not uploading
PostPosted: Mon Nov 08, 2004 2:45 pm 
8086
8086

Joined: Sat Nov 06, 2004 2:24 pm
Posts: 6
Location: http://twirp.net
for some reason the image isn't uploading and i can't seem to find the problem :'(
so here's my form:
Code:
echo"<form action=\"index.php\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"mode\" value=\"adsm\">";
echo"File: <input type=\"file\" name=\"file\"><br>";
echo"Code: <input name=\"code\"><br>";
echo"<input type=\"submit\" value=\"Add!\">";
echo"</form>";


and my processing page:
Code:
<?php
$copy = copy($file,"smile/$file_name");
if($copy){
$q = "INSERT INTO mbsmile (code,img) VALUES ('$code','$file_name')";
$result = mysql_db_query($db,$q);
if($result){
    echo"smiley uploaded successfully";
}else{
    echo"An error occured...";
}
}else{
   echo"image couldn't be uploaded";
}
?>


please help...
the error i get:
Warning: copy(!.gif): failed to open stream: No such file or directory in /home/twirp35/public_html/naruto/adsm.php on line 2...


Top
  Profile  
 
 Post subject: Re: Image not uploading
PostPosted: Tue Nov 09, 2004 8:11 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24218
Location: Granite Heaven
Code:
Warning: copy(!.gif): failed to open stream: No such file or directory in /home/twirp35/public_html/naruto/adsm.php on line 2...


So, it is choking on the second line of your php script ... this one:

Code:
$copy = copy($file,"smile/$file_name");


I would start by checking to ensure that the correct file name is being passed, and that the file exists in that directory (/home/twirp35/public_html/naruto/adsm.php)


Top
  Profile  
 
 Post subject:
PostPosted: Thu Jan 06, 2005 7:03 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Wed Jun 16, 2004 11:30 am
Posts: 368
Location: San Antonio, TX
For starters your form has some errors. I added a MAX_FILE_SIZE field for the max size of the image in bytes. You also need to specify an input type for the Code field.

Code:
<?
echo"<form action=\"index.php\" enctype=\"multipart/form-data\" method=\"POST\"><input type=\"hidden\" name=\"mode\" value=\"adsm\">";
echo "<!-- MAX_FILE_SIZE must precede the file input field --><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"5242880\" />";
echo"File: <input type=\"file\" name=\"file\"><br>";
echo"Code: <input name=\"code\"><br>";
echo"<input type=\"submit\" value=\"Add!\">";
echo"</form>";
?>


Your page handling the uploaded file also doesn't properly handle the uploaded file. Php stores uploaded files in a temp location until you copy them over. After the script is done running the temp files are removed. This rewritten script should work for you. You will need to update the $uploaddir value with the full unix path to where you want these smileys stored.

Code:
<?
$uploaddir = "~/smile/"; // remember the trailing slash!
/* Retrieve data from POST */
$MAX_FILE_SIZE = $_POST['MAX_FILE_SIZE'];
$code = $_POST['code'];
$file_name = $_FILES['file']['name'];

/* Error check uploaded file */
if($_FILES['file']['name'] == '') {
  echo "You did not select a file to upload" . $_FILES[$file]['name'];
} elseif($_FILES['file']['size'] == 0) {
  echo 'There appears to be a problem with the file your are uploading, it has a size of 0';
} elseif($_FILES['file']['size'] > $MAX_FILE_SIZE) {
  echo 'The file you selected is too large' . $MAX_FILE_SIZE;
} else {
  $uploadfile = $uploaddir. $_FILES['file']['name'];
  if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
    echo 'Upload file success!<br>';
    $q = "INSERT INTO mbsmile (code,img) VALUES ('$code','$file_name')";
    $result = mysql_db_query($db,$q) or die("Couldn't execute query.<br>" . mysql_error() . "<br>$q<br>");
  } else {
    echo 'There was a problem uploading your file.<br>';
    print_r($_FILES);
  }
}
?>


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group