PHP - Php.ini Upload Error
i have this in my php.ini
Quote ;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; ; Whether to allow HTTP file uploads. ; http://php.net/file-uploads file_uploads = On ; Temporary directory for HTTP uploaded files (will use system default if not ; specified). ; http://php.net/upload-tmp-dir upload_tmp_dir = "c:/wamp/tmp" ; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 32M but when i upload i get error # 1 which is The uploaded file exceeds the upload_max_filesize directive in php.ini what am i doing wrong? <body> <form enctype="multipart/form-data" action="uploadfile.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="10485760" /> Choose a file to upload: <input name="file" type="file" /><br /> <input type="submit" value="Upload File" /> </form> </body> <?php include 'db_fns.php'; function RemoveExtension($strName) { $ext = strrchr($strName, '.'); if($ext !== false) { $strName = substr($strName, 0, -strlen($ext)); } return $strName; } $name = $_FILES["file"]['name']; $type = $_FILES["file"]['type']; $error = $_FILES["file"]['error']; $size = $_FILES["file"]['size']; $tmp = $_FILES["file"]["tmp_name"]; $date = date("Y-m-d"); echo $_FILES["file"]['error']; if($type == 'audio/mpeg' || $type == ' audio/mp3'){ $song_name = RemoveExtension($name); $query = "INSERT into uploads(song_name, created_at) VALUES ('$song_name', '$date')"; $result = mysqli_query($link, $query); $id = mysqli_insert_id($link); move_uploaded_file($tmp, "uploads/" . $id . ".mp3"); echo "your link is <a href='play.php?id=$id'> here</a>"; }else{ echo 'File must be in mp3 format'; } ?> Similar Tutorialsfiles that upload during insert/submit form was gone , only files upload during the update remain , is the way query for update multiple files is wrong ? $targetDir1= "folder/pda-semakan/ic/"; if(isset($_FILES['ic'])){ $fileName1 = $_FILES['ic']['name']; $targetFilePath1 = $targetDir1 . $fileName1; //$main_tmp2 = $_FILES['ic']['tmp_name']; $move2 =move_uploaded_file($_FILES["ic"]["tmp_name"], $targetFilePath1); } $targetDir2= "folder/pda-semakan/sijil_lahir/"; if(isset($_FILES['sijilkelahiran'])){ $fileName2 = $_FILES['sijilkelahiran']['name']; $targetFilePath2 = $targetDir2 . $fileName2; $move3 =move_uploaded_file($_FILES["sijilkelahiran"]["tmp_name"], $targetFilePath2); } $targetDir3= "folder/pda-semakan/sijil_spm/"; if(isset($_FILES['sijilspm'])){ $fileName3 = $_FILES['sijilspm']['name']; $targetFilePath3 = $targetDir3 . $fileName3; $move4 =move_uploaded_file($_FILES["sijilspm"]["tmp_name"], $targetFilePath3); } $query1=("UPDATE semakan_dokumen set student_id='$noMatrik', email= '$stdEmail', surat_tawaran='$fileName', ic='$fileName1',sijil_lahir='$fileName2',sijil_spm= '$fileName3' where email= '$stdEmail'");
This is my first time ever working with this type of stuff with PHP. So, I basically got this code from a tutorial at Tizag on how to upload files to your webiste. But everytime I do, I get an error message. I don't get a PHP error, I just get it from the code. "There was an error uploading the file, please try again!" <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } else { $description = $_POST['description']; $description = mysql_real_escape_string($description); $ip = $_SERVER['REMOTE_ADDR']; $date = date('m-d-y'); $title = $_POST['title']; $title = mysql_real_escape_string($title); $query = mysql_query("SELECT COUNT(id) FROM mods"); $finish_query = mysql_fetch_assoc($query); $output = $finish_query['COUNT(id)'] + 1; echo $output; $_FILES['uploadedfile']['name'] = $output; echo $_FILES['uploadfile']['name']; $target_path = "mods/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The mod ". basename( $_FILES['uploadedfile']['name']). " has been uploaded. Check it out HERE."; mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')"); } else{ echo "There was an error uploading the file, please try again!"; } } include("includes/footer.php"); ?> Why does it give me the "There was an error uploading the file, please try again!" error message? I've checked through the code, and I've looked to see what is wrong. I'm thinking it MIGHT be because of: $target_path = $target_path . $output; if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip") { if(move_uploaded_file($output, $target_path)) { But, heres the full code: <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } else { echo "<a href='start_upload.php'>Upload</a> | <a href='search.php'>Search & Browse</a> | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>"; $description = $_POST['description']; $description = mysql_real_escape_string($description); $ip = $_SERVER['REMOTE_ADDR']; $date = date('m-d-y'); $title = $_POST['title']; $title = mysql_real_escape_string($title); $user = $_SESSION['SESSION']; $target_path = "mods/"; $query = mysql_query("SELECT COUNT(id) FROM mods"); $finish_query = mysql_fetch_assoc($query); $output = $finish_query['COUNT(id)'] + 1; $target_path = $target_path . $output; if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip") { if(move_uploaded_file($output, $target_path)) { echo "The mod ". basename($_FILES['file']['name']) . " has been uploaded. Check it out <a href='mods/". $output ."'>HERE.</a>"; mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')"); } else{ echo "There was an error uploading the file, please try again!"; } } else { echo "You cannot use a .". pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION) ." extension! .zip is currently the only file extension allowed."; } } include("includes/footer.php"); ?> Hi. I have the following code: <?php $host=""; $username=""; $password=""; $db_name=""; $tbl_name="topic"; // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $name=$_POST['name']; $detail=$_POST['details']; $sql="INSERT INTO $tbl_name(topic, detail, datetime)VALUES('$name', '$detail', NOW())"; $result=mysql_query($sql); if($result){ echo("Topic created. "); $sql3="SELECT max(id) FROM $tbl_name"; $result3=mysql_query($sql3); $tbl_name2="top_img"; for($i=1; $i<11; $i++){ $uploaddir = '/imgs/'; $uploadfile = $uploaddir . basename($_FILES['img'.$i]['name']); echo '<pre>'; if (move_uploaded_file($_FILES['img'.$i]['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } }} echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; echo("<br><br><a href='site.html'>HOME</a>"); ?> And the error message: Quote Topic created. PHP Error Message Warning: move_uploaded_file(/imgs/Sunset.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/a7129718/public_html/test/add_topic.php on line 28 PHP Error Message Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php73HyFd' to '/imgs/Sunset.jpg' in /home/a7129718/public_html/test/add_topic.php on line 28 Free Web Hosting Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Possible file upload attack! Here is some more debugging info:Array ( [img1] => Array ( [name] => Sunset.jpg [type] => image/jpeg [tmp_name] => /tmp/php73HyFd [error] => 0 [size] => 71189 ) [img2] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 bla bla bla Any idea what the problem might be? Thanks in advance. Bye. Hi want to upload file using form's input type="file" then i want to display it on another page, As i am new to PHP i am doing this step by step so that I can test each step and go ahead. My first step is to upload file and check if its uploading in temp location.. I got same code from net.. I am using notepad++ thats why not sure abt syntax error, What I did is: <html> <body> <form action="index.php" method="POST" enctype="multipart/form-data"> Image: <input type="file" name="image"> <input type="submit" value="Upload"> </form> <?php mysql_connection("localhost","root","admin") or die(mysql_error()); mysql_select_db("searchdeals") or die(mysql_error()); echo $file = $_FILES['image']['tmp_name']; ?> </body> </html> Hi all, I'm using some code that I got from the net (I forget where but all credit to the author). I've tried to adapt it to suit my own needs (almost suceeded?). I have an upload page with 5 file uploads which is processed by this script: (I've annotated where I think the problems may be) UPLOAD FORM <table width="600" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#993399"> <tr> <form action="../uploads/upload2.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#993399"> <tr> <td><div align="center"><strong><h3>Upload your files</h3></strong></div></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center"><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </td> </form> </tr> </table> Here is "uploads.php" <?php $path1= "../uploads/".$HTTP_POST_FILES['ufile']['name'][0]; $path2= "../uploads/".$HTTP_POST_FILES['ufile']['name'][1]; $path3= "../uploads/".$HTTP_POST_FILES['ufile']['name'][2]; $path4= "../uploads/".$HTTP_POST_FILES['ufile']['name'][3]; $path5= "../uploads/".$HTTP_POST_FILES['ufile']['name'][4]; copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2); copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3); copy($HTTP_POST_FILES['ufile']['tmp_name'][3], $path4); copy($HTTP_POST_FILES['ufile']['tmp_name'][4], $path5); include '../includes/smile.php'; echo "<table width=\"900\"height=\"180\"cellpadding=\"5\" cellspacing=\"5\" background=\"../images/upbg.png\" align=\"center\"> <tr><td align=center><img src=\"$path1\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path2\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path3\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path4\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path5\" width=\"100\" height=\"100\"></td></tr></table>"; $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; $filesize4=$HTTP_POST_FILES['ufile']['size'][3]; $filesize5=$HTTP_POST_FILES['ufile']['size'][4]; if($filesize1 && $filesize2 && $filesize3 && $filesize4 && $filesize5 !=0) // possible error? { echo "<h3 align=center><img src=\"../images/niceone.png\"></h3>"; include '../includes/smilefoot.php'; } else { echo "<meta http-equiv='Refresh' content='0; url=../includes/fail.php'>"; // possible error? } ?> It took me an entire day to get it at this level of functionality where if you sucessfully upload your files you get a success message on the same page but otherwise are redirected to a failure page. The problem is, if you don't upload a file for each of the 5 form inputs, you get the succes message and then redirected to the fail page. Someone who actually knows something about php will probably see a solution straight away but I don't know anything much really and I have few ideas on how to fix this. I am beginning to suspect that it is my redirect method but I have no idea how to do it differently. I'd be really grateful if someone could explain what I'm doing wrong here, this is for my personal family site and I want it to be good. It took me a week to do the login! What I'd love to achieve is exactly the same as the attachment box(es) right below where I am typing now. I have attached my two relavent pages. Thanks in advance. Paul [attachment deleted by admin] Hello, i'm trying to upload a file through a page, on a local wamp server. Here's the code i'm using: Code: [Select] <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Upload" /> </form>This is the form i'm using to pass my file Code: [Select] <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"] . "<br />"; if (move_uploaded_file($_FILES["file"]["tmp_name"], $_SERVER['DOCUMENT_ROOT']. "/template_example/slideshow/images/" . $_FILES["file"]["name"])) { echo "Stored in: " . $_SERVER['DOCUMENT_ROOT'] . "localhost/template_example/slideshow/images/" . $_FILES["file"]["name"]; } } ?> The problem comes up if i try to upload an image file of size 1,07 MB. upload_max_filesize on my php.ini is at 2M. I also tried changing it to 2000M just to see if thats the problem. The error code i'm getting is 2 which means: Value: "2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form." from what i got on the internet. My operating system is windows XP SP2 and i have wamp server installed. Please help! I am trying to uploading images when i submit the images i get an error Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6 How do i fix this my code is below. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>upload</title> </head> <body> <?php //connect to MySQL $db = mysql_connect('localhost', 'user', 'pass') or die ('Unable to connect. Check your connection parameters.'); mysql_select_db('testdb', $db) or die(mysql_error($db)); //change this path to match your images directory $dir ='productimages'; //change this path to match your thumbnail directory $thumbdir = $dir . 'productthumb'; //change this path to match your fonts directory and the desired font putenv('GDFONTPATH=' . 'C:/Windows/Fonts'); $font = 'arial'; // handle the uploaded image if ($_POST['submit'] == 'Upload') { //make sure the uploaded file transfer was successful if ($_FILES['uploadfile']['error'] != UPLOAD_ERR_OK) { switch ($_FILES['uploadfile']['error']) { case UPLOAD_ERR_INI_SIZE: die('The uploaded file exceeds the upload_max_filesize directive ' . 'in php.ini.'); break; case UPLOAD_ERR_FORM_SIZE: die('The uploaded file exceeds the MAX_FILE_SIZE directive that ' . 'was specified in the HTML form.'); break; case UPLOAD_ERR_PARTIAL: die('The uploaded file was only partially uploaded.'); break; case UPLOAD_ERR_NO_FILE: die('No file was uploaded.'); break; case UPLOAD_ERR_NO_TMP_DIR: die('The server is missing a temporary folder.'); break; case UPLOAD_ERR_CANT_WRITE: die('The server failed to write the uploaded file to disk.'); break; case UPLOAD_ERR_EXTENSION: die('File upload stopped by extension.'); break; } } Can anyone help me to fix this two error?
#upload directory path mysqli_select_db($conn, "test2") or die(mysql_error()); Thank you !
hi, i am trying to code a file uploader in php using IIS server this is the code of the form: <html><body> <form method="post" enctype="multipart/form-data" action="processform.php"> <input type="hidden" name="MAX_FILE_SIZE" value="200000"> <input type="file" name="thefile"><br/> <input type="submit" value="Submit File...."> </form> </body></html> this is the code of processform.php <?php $upload_dir = "C:/Inetpub/wwwroot/cbt/upload/"; $upload_file = $upload_dir . basename($_FILES['thefile']['name']); if(copy($_FILE['thefile']['tmp_name'],$upload_file)){ echo "File copy was Successful!"; } else { echo "Oops... something went wrong..."; print_r($_FILES); } ?> now the problem is each time i try to click on the submit button after browsing any file it shows the message : Oops... something went wrong...Array ( [thefile] => Array ( [name] => 1.jpeg [type] => image/jpeg [tmp_name] => C:\temps\php13.tmp [error] => 0 [size] => 59592 ) ) help me guys...... wats the problem with the code ? Need some help with this script. I'm looking to limit the type of file you can upload to my server the script uploads ok but i when i try t view the uploaded file but i get an error cant find file extension for this file what am i doing wrong as i'm very new to php . Thank for your help in advance Code: [Select] <?php $allowedExtensions = array("jpg","jpeg","gif","png","bmp"); foreach ($_FILES as $image) { if ($image['tmp_name'] > '') { if (!in_array(end(explode(".", strtolower($image['name']))), $allowedExtensions)) { die($image['name'].' is an invalid file type!<br/>'. '<a href="javascript:history.go(-1);">'. '<< Go Back</a>'); } } } $target = "testimages/"; $target = $target . basename( $_FILES['image']['name']); // $company=$_POST['company']; $image=($_FILES['image']['name']); mysql_connect("localhost", "user", "pass") or die(mysql_error()) ; mysql_select_db("testupload") or die(mysql_error()) ; mysql_query("INSERT INTO `table` (company, image) VALUES ('$company', '$image')") ; if(move_uploaded_file($_FILES['image']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { echo "Sorry, there was a problem uploading your file."; } ?> Hi Guys, What I am doing is making a backup of a folder by zipping it on a server which is outside of web root, downloading a local copy to a web accessible place and then uploading the zip file back to the non web folder. I am using phpseclib's sftp to achieve this. The error I have is that when the file is uploaded to the non web area, the file is 0 bytes and cannot be used, the copy stored on the web accesible area is fine? The code I am using: Code: [Select] <?php if(isset($_GET['backup'])) { $worldname = $_GET['backup']; //checks to see if upload if(!is_dir("backups")) //create backup directory if not exist { mkdir("backups", 0777); } mkdir("backups/".$worldname, 0777); //make filename directory $main_dest = "backups/".$worldname.""; //set backup destination $delpath = "backups/"; //path which will be deleted later $sftp = new Net_SFTP($host); $sftp->login($root_user, $root_pass); //login to sftp $get = "/root/minecraft/".$worldname."/"; //get correct directory for backup get_folder($sftp, $get, $main_dest ); //execute command Zip('backups/'.$worldname.'','backups/'.$worldname.''.date("dmy-H:i").'.zip'); //make zip of folder $sftp->put('/root/minecraft/backups/'.$worldname.''.date("dmy-H:i").'.zip','backups/'.$worldname.' '.date("dmy-H:i").'.zip',NET_SFTP_LOCAL_FILE); //put zip file from web folder to root/backup folder rrmdir($delpath); //delete old folder (function below) //unlink('backups/'.$worldname.''.date("dmy-H:i").'.zip'); deletes web copy header('Location: index.php'); } The line which is causing the issue is: Quote $sftp->put('/root/minecraft/backups/'.$worldname.''.date("dmy-H:i").'.zip','backups/'.$worldname.' '.date("dmy-H:i").'.zip',NET_SFTP_LOCAL_FILE); The function is basically $remotefile, $data, $mode Can anyone take a guess at what is causing the issue? PHP max upload size is 200mb, the files are around 5mb, the timeout is 360 seconds? Cheers Dave[/code] Hi I have an upload script which uploads an image then resizes The error Code: [Select] Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 7776 bytes) in Dir/UploadScript.php on line 234 The code function $strNewFileName = date("YmdHis").rand(0,5000).".".$this->strFileExt; $this->strNewFileName = $strNewFileName; $strDir = $_SERVER['DOCUMENT_ROOT'].$this->strSaveDir.$strNewFileName; $strTNDir = $_SERVER['DOCUMENT_ROOT'].$this->strSaveDir."tn_".$strNewFileName; move_uploaded_file($this->arrUploadFile['tmp_name'], $strDir); $image_p = imagecreatetruecolor($this->intNewWidth, $this->intNewHeight); switch($this->strFileExt){ case "jpg": $image = imagecreatefromjpeg($strDir); break; case "gif": $image = imagecreatefromgif($strDir); break; case "png": $image = imagecreatefrompng($strDir); break; } imagecopyresampled($image_p, $image, 0, 0, 0, 0, $this->intNewWidth, $this->intNewHeight, $this->intCurWidth, $this->intCurHeight); $blnSuccessUpload = false; switch($this->strFileExt){ case "jpg": if(imagejpeg($image_p, $strTNDir)){ $blnSuccessUpload = true; } break; case "gif": if(imagegif($image_p, $strTNDir)){ $blnSuccessUpload = true; } break; case "png": if(imagepng($image_p, $strTNDir)){ $blnSuccessUpload = true; } } imagedestroy($image_p); return $blnSuccessUpload; the Line causing issues (234) is Code: [Select] $image = imagecreatefromjpeg($strDir); Now that image is created but the TN is not //Edit Just a note. I have ini_set('memory_limit', 16MB); if you notice the allocated memory is less than the memory allowed. I'm working on a fairly straight forward facet of an image gallery application where the client can upload a zip file full of photos and it extracts them one by one to a temp folder, resizes it and moves it to the pic folder, creates a thumbnail, then deletes it from the temp folder All that works fine, but I'm testing it in a situation where I'm uploading a 56 MB zip file, my max_file_size is 128 MB, and it gives me the 'max_file_size' error. Anyone else ever have this problem or have any ideas on how to solve it? The Script:
<?php if (isset($_POST['submit'])) { $j = 0; //Variable for indexing uploaded image $target_path = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/uploads/"; //Declaring Path for uploaded images for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) $file_extension = end($ext); //store extensions in the variable $new_image_name = md5(uniqid()) . "." . $ext[count($ext) - 1]; $target_path = $target_path . $new_image_name;//set the target path with a new name of image $j = $j + 1;//increment the number of uploaded images according to the files in array if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded. && in_array($file_extension, $validextensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>'; for ($i = 0; $i < count($_FILES['file']['name']); $i++) { $tqs = "INSERT INTO images (`original_image_name`, `image_file`, `date_created`) VALUES ('" . $_FILES['file']['name'][$i] . "', '" . $new_image_name . "', now())"; $tqr = mysqli_query($dbc, $tqs); } // To create the thumbnails. function make_thumb($src, $dest, $desired_width) { /* read the source image */ $source_image = imagecreatefromjpeg($src); $width = imagesx($source_image); $height = imagesy($source_image); /* find the "desired height" of this thumbnail, relative to the desired width */ $desired_height = floor($height * ($desired_width / $width)); /* create a new, "virtual" image */ $virtual_image = imagecreatetruecolor($desired_width, $desired_height); /* copy source image at a resized size */ imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height); /* create the physical thumbnail image to its destination */ imagejpeg($virtual_image, $dest); } $src = $target_path; $dest = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/thumbs/"; $desired_width = 100; make_thumb($src, $dest, $desired_width); } else {//if file was not moved. echo $j. ').<span id="error">please try again!.</span><br/><br/>'; } } else {//if file size and file type was incorrect. echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>'; } } } ?>With this: $dest = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/thumbs/";I get this error message: Warning: imagejpeg(C:/xampp/htdocs/gallerysite/multiple_image_upload/thumbs/): failed to open stream: No such file or directory in C:\xampp\htdocs\gallerysite\multiple_image_upload\upload.php on line 49With this: $dest = "http://localhost/gallerysite/multiple_image_upload/thumbs/";I get this error message: Warning: imagejpeg(http://localhost/gallerysite/multiple_image_upload/thumbs/): failed to open stream: HTTP wrapper does not support writeable connections in C:\xampp\htdocs\gallerysite\multiple_image_upload\upload.php on line 49When I try deleting the "thumbs" folder and then try to upload an image, then I get this error message: Warning: imagejpeg(C:/xampp/htdocs/gallerysite/multiple_image_upload/thumbs/): failed to open stream: Invalid argument in C:\xampp\htdocs\gallerysite\multiple_image_upload\upload.php on line 49The spot of line 49 is this, at the spot where the script creates the thumbnails: /* create the physical thumbnail image to its destination */ imagejpeg($virtual_image, $dest); }Also, with this part right here I am not getting an error message, which means that this part works fine in comparison: $target_path = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/uploads/"; //Declaring Path for uploaded imagesThe script itself works fine. The script also uses javascript for multiple image upload. I am using XAMPP. The folder "thumbs" is set to "read-only", when I try to uncheck the "read-only" option in the properties in Windows then it sets itself back again to "read-only". Then again, the script works fine when it comes to the "uploads" folder. This is mentioned in comparison to the "thumbs" folder. Any suggestions on how to solve this? EDIT: I am using XAMPP. The folder "thumbs" is set to "read-only", when I try to uncheck the "read-only" option in the properties in Windows then it sets itself back again to "read-only". I am wondering if I would have issue that the option sets itself back again with Linux? Edited by glassfish, 11 October 2014 - 05:35 PM. Goal: To have a gallery that downloads images from the folder I previously uploaded to in a previous script. Bug: When I load the page the thumbnail comes up as broken and when I click on the thumbnail to get the bigger picture it comes up with the following error message: "Firefox doesn't know how to open this address, because the protocol (c) isn't associated with any program." <?php include 'db.inc.php'; //connect to MySQL $db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die ('Unable to connect. Check your connection parameters.'); mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db)); //change this path to match your images directory $dir ='C:/x/xampp/htdocs/images'; //change this path to match your thumbnail directory $thumbdir = $dir . '/thumbs'; ?> <html> <head> <title>Welcome to our Photo Gallery</title> <style type="text/css"> th { background-color: #999;} .odd_row { background-color: #EEE; } .even_row { background-color: #FFF; } </style> </head> <body> <p>Click on any image to see it full sized.</p> <table style="width:100%;"> <tr> <th>Image</th> <th>Caption</th> <th>Uploaded By</th> <th>Date Uploaded</th> </tr> <?php //get the thumbs $result = mysql_query('SELECT * FROM images') or die(mysql_error()); $odd = true; while ($rows = mysql_fetch_array($result)) { echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">'; $odd = !$odd; extract($rows); echo '<td><a href="' . $dir . '/' . $image_id . '.jpg">'; echo '<img src="' . $thumbdir . '/' . $image_id . '.jpg">'; echo '</a></td>'; echo '<td>' . $image_caption . '</td>'; echo '<td>' . $image_username . '</td>'; echo '<td>' . $image_date . '</td>'; echo '</tr>'; } ?> </table> </body> </html> Any help appreciated. So I wanted to create stickers on my forum where people type in say ":Blobby-Tired" and then instead of the comment showing ":Blobby-Tired" it shows an html image tag displaying a picture of Blobby in the comment box So I created the following page CommentUpload.php However my sql fails to insert it despite the fact when I "echo $new" it shows the image on the page correctly And it can't be my sql insert code as if I change $new variable for "$BodyText" int he SQL query it it inserts ":Blobby-Tired" OK?
<?php include 'dbconnect.php'; session_start(); if(isset($_POST["submit"]) && !empty($_POST["CommentText"])){ $id = intval($_SESSION['id']); echo $_SESSION['id'] . '<p> </p>' ; $BodyText = $conn -> real_escape_string($_POST['CommentText']) ; $User = $_SESSION['username']; //Replace flairs with <img> tags /*not working currently) */ $new = str_replace(":Blobby-Tired","<img src='flairs/Blobby-Tired.jpg'> </img>","'$BodyText'"); echo "$new"; /************************/ $sql = "INSERT INTO Posts (User, CommentText, IdOfThread) VALUES ('$User','$new','$id')"; if (mysqli_query($conn, $sql)) { echo "New record has been added successfully !"; } else { echo "Error: " . $sql . ":-" . mysqli_error($conn); } mysqli_close($conn); } ?> Edited April 28 by Fishcakes I have code written for image uploading, but it doesn't allow multiple images on a single upload, and doesn't re-size. Anyone willing to share a good upload script that will do the following?: -Allow multiple image uploads (10+ per submission), -Re-size images on upload, and -Rename images. Thanks Brett |