PHP - Temporary Download Files
Hi Guys I trying to download files and I have this error message, hopelly you guys can help me please
Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 14
Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 15 Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 16 Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 17 Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 18 This is the code I use to force the download <?php include('core/inc/init.inc.php'); if(isset($_GET['file_id'])) { $file_id=(int)$_GET['file_id']; $file=mysql_query("SELECT file_name, file_expiry FROM files WHERE file_id=$file_id"); if(mysql_num_rows($file)!=1){ echo'Invalid file Id'; }else{ $row=mysql_fetch_assoc($file); if ($row['file_expiry']<time()){ echo'This file has expired'; }else{ $path="core/files/{$row['$file_name']}"; header('Content-Type:application/octet-stream'); header('Content-Description:File Transfer'); header('Content-Transfer-Encoding:binary'); header("Content-Disposition:attachment;filename=\"{$row['file_name']}\""); header('Content-Length:'.filesize($path)); readfile($path); } } } ?>Thank you for your help..... Similar TutorialsI'm modifying a script I built a few months ago to allow someone to upload an attachment via a form and then email it off. It is expected that this form will receive a lot of hits and so it won't be possible to store the attachment in a folder before emailing it out (right away). Problem: If I skip the move_uploaded_file part, and just attach the tmp_name the tmp_name is how I receive it rather than the PDF that it actually is. How can i change the documents name before sending it off, without saving it to a general location. My worry with saving it is, someone uploads their copy and at the exact moment it's supposed to email off, someone somewhere else uploads theirs and it overwrites the first persons and then the email gets sent with the newest persons data. index.php Code: [Select] <form action="process.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> process.php Code: [Select] <?php print_r($_FILES); if ($_FILES["file"]["type"] == "text/plain") { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> I've searched the forum, and haven't yet found what I need. I have a long list of PDF files: http://www.iampeth.com/vintage_magazines.php How can I track the number of downloads for each file? Hey guys, im starting out on my php journey with a small question. I have a small uploading site and i want to allow php uploads. Once uploaded, you get a direct upload link, and i want the file to download, rather than execute. How can this be done? Thanks! Hi guys i am kinda stuck at a part where i want a download button to prompt out two download windows in a click. Currently i am able to prompt out one download window only. I have tried putting another header line of Content Disposition but it doesn't work..i will appreciate if you guys can help me out, thanks! The desired scenario will be WinSCP.exe download prompt will appear first, follow by auditgroup.bat $file1 = "WinSCP.exe"; $file = "auditgroup.bat"; //Set headers header("Cache-Control: private"); header("Expires: 0"); header("Pragma: cache"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: ASCII"); //Read the file from disk readfile($file); Hi PHP Community, I have this class in my DOCMAN script and would like to add aditional functionality to watermark existing PDF files: Code: [Select] class DOCMAN_File { /** * @access public * @var string */ var $path = null; /** * @access public * @var string */ var $name = null; /** * @access public * @var string */ var $mime = null; /** * @access public * @var string */ var $ext = null; /** * @access public * @var string */ var $size = null; /** * @access public * @var string */ var $date = null; /** * @access private * @var string */ var $_err = null; /** * @access private * @var boolean */ var $_isLink; function DOCMAN_File($name, $path) { $path = mosPathName( $path ); if (!is_dir( $path )) { $path = dirname( $path ); } $this->name = trim($name); $this->path = $path; if( strcasecmp( substr( $this->name , 0, _DM_DOCUMENT_LINK_LNG ) , _DM_DOCUMENT_LINK )==0){ $this->_isLink = true; $this->size = 0; $this->mime = 'link'; }else{ $this->_isLink = false; $this->size = filesize($this->path."/".$this->name); $this->mime = DOCMAN_MIME_Magic::filenameToMIME($this->name, false); } $this->ext = $this->getExtension(); } /** * Download or view a file from the server * @desc This is the function handling files downloading using HTTP protocol * @param void * @return void */ function download() { $user_agent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ? $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT; //Fixed [#2534] clean all output buffers (needs PHP > 4.2.0) /* while (ob_get_level()) { * ob_end_clean(); }*/ // Fix [3164] while (@ob_end_clean()); if( $this->_isLink ){ header( "Location: " . substr( $this->name , 6 ) ); return; } $fsize = filesize($this->path."/".$this->name); $mod_date = date('r', filemtime( $this->path.'/'.$this->name ) ); $cont_dis = 'attachment;'; if(isset($_REQUEST['mode'])) $cont_dis = ($_REQUEST['mode'] == 'view') ? 'inline;' : 'attachment;'; header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Expires: 0"); header("Content-Transfer-Encoding: binary"); header('Content-Disposition:' . $cont_dis .'";' . ' filename="' . $this->name . '";' . ' modification-date="' . $mod_date . '";' . ' size=' . $fsize .';' ); //RFC2183 header("Content-Location: ". $this->path . '/' . $this->name ); header("Content-Type: " . $this->mime ); // MIME type header("Content-Length: " . $fsize); // No encoding - we aren't using compression... (RFC1945) // header("Content-Encoding: "); readfile($this->path."/".$this->name); // The caller MUST 'die();' } function exists() { if( $this->_isLink ){ return true; } return file_exists($this->path."/".$this->name); } function isLink(){ return $this->_isLink ; } /** * Get file size * * @desc Gets the file size and convert it to friendly format * @param void * @return string Returns filesize in a friendly format. */ function getSize() { if( $this->_isLink ){ return 'Link'; } $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; $size = $this->size; if ($size) { if ($size < $kb) { $file_size = "$size Bytes"; } elseif ($size < $mb) { $final = round($size/$kb,2); $file_size = "$final KB"; } elseif ($size < $gb) { $final = round($size/$mb,2); $file_size = "$final MB"; } elseif($size < $tb) { $final = round($size/$gb,2); $file_size = "$final GB"; } else { $final = round($size/$tb,2); $file_size = "$final TB"; } } else { if( $size == 0 ) $file_size = "Empty!"; else $file_size = "ERROR"; } return $file_size; } /** * @desc Gets the extension of a file * @return string The file extension */ function getExtension() { if( $this->_isLink ) return "lnk"; $dotpos = strrpos($this->name, "."); if ($dotpos < 1) return "unk"; return substr($this->name, $dotpos + 1); } function getDate($type = 'm') { if( $this->_isLink ){ return ""; } $date = ''; switch($type) { case 'm' : $date = filemtime($this->path."/".$this->name); break; case 'a' : $date = fileatime($this->path."/".$this->name); break; case 'c' : $date = filectime($this->path."/".$this->name); break; } return date ("m.d.y - H:i:s", mosFormatDate($date)); } } I found this function on the net and it works fast. But because I'm newbie I have problem in implementing it correctly to class: Code: [Select] function WaterMark($filename){ $tempfile=tempnam('/path/to/directory/tmp,'temp.pdf'); $watermark = "/path/to/directory/htdocs/components/com_docman/includes_frontend/water.pdf"; system("pdftk $filename stamp $watermark output $tempfile dont_ask", $errcode); if (!$errcode && $ih=fopen($tempfile, 'r')) { header('Content-Type: application/pdf'); fpassthru($ih); fclose($ih); } else { print "Whoops"; } unlink($tempfile); } Here is frontend use of class. Code: [Select] $downloadDoc = new DOCMAN_File($document->dmfilename,$_DOCMAN->getCfg('dmpath')); $downloadDoc->download(); For now I only managed to get it working to watermark PDF file for view mode but not before download mode as attachment. Function is working fine by itself but not when integrated in class. I'm getting really frustrated . Please help me!?! Thank you everybody. Al Hi, how much bandwidth is used for 1000 downloads per day or for each download? Is it safe to have no download limits? Thanks
I have a Joomla website having one folder for audio files in it and their links are saved in database. Now I want to show two calendars to the user at front end, so that they can choose that from when to from he want to download the audio files? for e.g he can select june-2-2014 in one calendar and august-2-2014 in second calendar, now on clicking download button the files residing between the two specific dates must get archived into one zip file and then start downloading... i have a reference link for creating a zip and downloading the zip :http://coursesweb.ne...-archive-php_cs now i am stuck that how to get the selection of user from calendar , save it into the array , and from the array get the files from the folder matching the array indexes and then zip , download them. please tell me how to achieve this task ? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=345265.0 My users table on my forum is what gets checked everytime a user refreshes to authentic them.
When killing a monster, I want users to be able to grab items and it will insert them into their inventory. I have this part done already. But I want them to have a plethora of loot available that drops from a mob, and once they click the specific item it will then be inserted into their inventory (server database).
I'm storing the Temporary Item Data in a PHP session variable. Once they kill a monster, the Tempory Item Data variable get's filled with the specific loot and then the user will have the option to choose what items they want to go into their inventory.
My problem is, if they open the game in a new browser they will get a new session id. Since I'm authenticating them through my users table, can I just make a new column called session_id and just use php's session_id() before every session start so no matter which browser they're on they will have the same session right?
You might think, well why dont you just store the temporary item data in a mysql field or rows instead? I want to try to minimize mysql usage as much as possible, as players will be CLICKING a lot to kill mobs, it is most likely very mysql demanding as well and I want to be intuitive about it. I just want to use temporary session data for the loot. Then once the user clicks an item they want, it is EXTRACTED from their tempory item data variable, then I will use MYSQL to insert those items into their inventory.
Is this a fair and intuitive way to do temporary data for item loot? For example, in action RPG's like Path of Exile you kill a group of mobs and you see a shit ton of loot on the floor. (I imagine that loot is just temporary waiting for someone to pick it up right?) Once you do pick it up, mysql is then called to save it right? That's the same logic I have with my web based game. Is using a session variable to store that temporay loot.
Is this an intuitive way to do this, or are there other ways?
Edited by Monkuar, 24 November 2014 - 01:24 AM. I'm using a popular PHP script for my web site, which uses main_1.htm for the header and footer, and inner_index.htm for the main part of the home page. Also, of course it has index.php. How can I set up a duplicates of these files to work on and test changes to the home page, before I actually deploy the changes on to my live site's home page? Thanks After the file gets uploaded, I intend the file to become renamed, and then moved to its destination folder. Though to move the file, I need the newly renamed file name and also its location, which is the temporary folder, and the latter describes my question. This is the script as follows: Code: [Select] $avatar_tmp = $_FILES['avatar_upload']['tmp_name']; // Rename the file into a more usable file name $new_file_name = $user_name . '_' . rand(111111, 999999) . '.jpg'; rename($avatar_tmp, $new_file_name); // Move the uploaded file on the disk to its folder // The directory of the temporary folder is needed in front of the new_file_name variable move_uploaded_file ($new_file_name, $target); The directory of the temporary folder is needed in front of the new_file_name variable and my question is, is there any function, to get the directory of the temporary folder for the uploaded file? So I can insert it in front of the new_file_name variable and move it out of the folder to its destination folder? Can anyone tell me, how the temporary file names (name of the file which is created in the 'tmp' dir ) generated by PHP when the files are uploaded ? Are there any algorithms used ?
Basically I would like to place a link on my website and have the user download a file, but rather than just right clicking and choosing save target as, the link must be clicked, on the next page the file is fetched and then the client can download the file. How would I go about setting this up please? I have this interesting problem, I think I know how to do it.
In a java class I took there was a lab on swapping the values of variables and if there were two variables, you needed a third temporary value holder.
So this project I'm working on has a row output, currently the individual values are outputted as a concatenated string but ideally they would be independent rows with accompanying buttons.
One of those buttons is a ^ symbol, when you press this, ideally the row is moved up in ID putting the previous ID in front or ahead.
The problem is that the ID's / rows are not necessarily in sequential order.
So, when I recall a set of rows that have random sequential values for example, 2, 5, 27, 41, 43
and those are outputted by themselves, now becoming 0,1,2,3,4 respectively or 1,2,3,4,5
So when I try to move 43 to position 2, that's 4 positions away or 4 clicks of the ^ button.
Now how do you deal with that 4 difference and the difference of 41... ? thereby, when the initial set of rows are recalled again, the order is now, 43, 5, 27, 41, 2 Of course the ID I think remains the same but the data is switched... ? yeah I have to draw some pictures, but this isn't a current problem to fix, later on down the road after I update the interface.
here is a drawing to explain, I'm more of a visual person
wp_20150112_05_27_16_pro.jpg 59.67KB
0 downloads
Any ideas would be appreciated, otherwise I will post my solution when I come to it. Or I don't figure it out and find one.
thanks
Ok here is what i got so far and now I am stuck. The user enters a number of how many squares (rectangles is note accurate) they wish to calculate. If its between 1 and 100 it continues, if its any other number it tells you to put in a number between 1 and 100. That was easy for me to do. If the number is between 1 and 100 it creates and input for length, width and height of each rectangle. creating the variables as it goes, i.e. "length$i" when $i is the while counter and increases to the ammount of rectangles you wished to view. Again, not that hard for me. So I am at the point where is I put in 50 I get length1 - through length30, width1 - width50, and height1 - height50. THis works great. However I now what to store those variables and calculate the area of each one via a while look which again creates an area$i variable which can be added (it would create area1 - area50 which I then wish to add together) Here is what I have so far. <?php session_start(); if (isset($_REQUEST['numpack'])) { if ($_REQUEST['numpack'] <= 0 || $_REQUEST['numpack'] > 100 ) { $error = "Please enter a number between 1 and 100"; echo $error; ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <table width="0" border="0" cellspacing="5" cellpadding="5"> <tr> <td colspan="2">How many Squares</td> </tr> <tr> <td> <input name="numpack" type="text" size="4" maxlength="3"></td> <td><input type="submit" name="button" id="button" value="Submit"></td> </tr> </table> </form> <?php } else { ?> <form name="form2" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <?php $i=1; while($i<=ceil($_REQUEST['numpack'])) { ?> <table width="325" border="0" cellspacing="5" cellpadding="5" style="float: left;" class="aluminium"> <tr> <td align="center" rowspan="2"><span class="transparent" style="color: #FFF; font-weight: bold;"><?=$i; ?>.</span></td> <td align="center">L</td> <td align="center">x</td> <td align="center">W</td> <td align="center">x</td> <td align="center">H</td> </tr> <tr> <td align="center"><input name="length<?=$i; ?>" type="text" size="4" maxlength="3"></td> <td align="center">x</td> <td align="center"><input name="width<?=$i; ?>" type="text" size="4" maxlength="3"></td> <td align="center">x</td> <td align="center"><input name="height<?=$i; ?>" type="text" size="4" maxlength="3"></td> </tr> </table> <?php $i++; } ?> </form> <?php } } If (!isset($_REQUEST['numpack'])) { ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <table width="0" border="0" cellspacing="5" cellpadding="5"> <tr> <td colspan="2">How many Squares</td> </tr> <tr> <td> <input name="numpack" type="text" size="4" maxlength="3"></td> <td><input type="submit" name="button" id="button" value="Submit"></td> </tr> </table> </form> <?php } ?> Now I was reading up on session data and think this might be the best way to go, but again how do I do this? and two I want to make sure that if there are 2 people accessing it at the same time, it does not change the variables on them... (i.e. user one puts in 50 values, and user two puts in 50 different values I do not want cross contamination) Any ideas on how to proceed? Hello folks, well what I mean by temporary variables are variables like error messages or success messages that appear after a form has been submitted. I want to be able to kill these variables when the page is refreshed and return the page to its defualt state. For example, I'm making this simple page which is basically a form that ask users for some information, then upon submit, stores the in a database and prints a success message. If the form is filled out incorrectly or some form fields are left blank, then error messages are printed. What I really want is for these messages to disappear when the page is refreshed. My current model uses a second page to handle the form, and then upon succes or upon encountering an error, redirects to the form page, passing the error or success variables via the url to the form page where they are printed out. What can I do differently to achieve what I want (ie kill variables upon page refresh)? Below are the form page, and the page that handles the form respectively. Code: [Select] <form method="post" action="send_email.php"> <div id="contact_form"> <div align="left" class="green18">Contact Us</div> <br/> <br/> <label>Your Name:</label> <input class="texta" name ="name" size="20" maxlength="49"/> <br/> <br/> <div class ="error" style="position:relative;bottom:40px;left:128px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[0];?> </div> <label>Your Company Name:</label> <input class="texta" name ="company" size="30" maxlength="66"/> <br/> <br/> <div class ="error" style="position:relative;bottom:40px;left:128px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[1];?> </div> <label>Subject(Optional):</label> <input class="texta" name ="subject" size="20" maxlength="49"/> <br/> <br/> <label>Email:</label> <input class="texta" name ="email" size="20" maxlength="49"/> <br/> <br/> <div class ="error" style="position:relative;bottom:40px;left:128px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[2];?> </div> <label>Message:</label> <textarea style="float:left" class="" name ="message" cols="40" rows="3"> </textarea> <br/> <br/> <div class ="error" style="position:relative;bottom:-19px;left:-260px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[3];?> </div> <button class="button" type ="submit" name ="submit">Submit</button> <br/> <div id ="sent" > <?php //Retrieve the user id from send_email.php page $sent=$_GET['sent']; $send_msg = urldecode($sent); echo $send_msg; ?> </div> <!--closes sent--> </div> </form> Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset($_POST['submit'])) { $errors = array(); // Connect to the database. require('config/config.php'); //Check for errors. //Check to make sure they entered their name and it's of the right format. if (eregi ("^([[:alpha:]]|-|')+$", $_POST['name'])) { $a = TRUE; } else { $a = FALSE; $errors[0] = '*Please enter a valid name.'; } //Check to make sure they entered their company name. if (!empty ( $_POST['company'])) { $b = TRUE; } else { $b = FALSE; $errors[1] = '*Please enter company name.'; } //Check to make sure email is valid. if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { $c = TRUE; }else { $c = FALSE; $errors[2] = '*Please enter a valid email address.'; } //Check to make sure they entered their message. if (!empty ( $_POST['message'])) { $d = TRUE; } else { $d = FALSE; $errors[3] = '*Please enter your message.'; } //If no errors if (empty($errors)) { //Create variables for all the post values. $name = $_POST['name']; $company = $_POST['company']; $email = $_POST['email']; $message = $_POST['message']; $ip = $_SERVER[REMOTE_ADDR]; $date = (date("Y/m/d:G:i:s")); $timestamp = ( mktime(date(H), date(i), date(s), date(m) , date(d) , date(Y))); //Formulate the insert query. $query = "INSERT INTO emails ( email_id, name, company, email, message, ip, date,timestamp) VALUES ( 0, '$name','$company','email', '$message', '$ip' , '$date', '$timestamp' )"; $result = mysql_query($query) or die("Data could not be inserted into table because: " .mysql_error()); if (mysql_affected_rows() == 1) { // Display success message $sent_msg = "Your email has been sent. We will get back to you shortly."; $sent = urlencode($sent_msg); // Display contact page header("Location: contact_page.php?sent=$sent"); exit(); }else{die("There was a problem: " . mysql_error());} //Display error messages. } else {// if errors array is not empty //Confer the errors array into a string $errors_string = implode(",", $errors); //Encode the imploded string. $error_message = urlencode($errors_string); // Display page header("Location: contact_page.php?errors_string=$errors_string"); exit(); }//End of if there are errors. }//End of if submit. ?> Also, another problem I just noticed is that, the errors[3] variable isn't getting passed back to the form page. I don't know if it's because the url can only pass so much info to a second page. The page in question can be located he http://creativewizz.com/contact_page.php Bear with me, as I'm still quite new at PHP. I'm trying to figure out the best way to build a search function for a database that will eventually be quite large. The path of the search I'm building is to go from a straight-forward javascript and html search page, to a paginated search result. Then the user can narrow down those query results based on a new search of their results. In trying to get the pagination to work across several pages(unsuccessfuly, I might add), I've been learning about sessions and temporary tables. But, because the database will be very large, I'm wondering if they are the wrong way. Sessions have a time limit, and temporary tables delete once the connection is closed. Is it possible/feasible to build a permanent table that puts in the search variables, with a unique id and use this to manage the searches, pagination and all that? Then, at some point in the process, I can put code to delete the corresponding row (or even make it a saveable search). Maybe somebody sees where I'm going with this and can describe it better than me? I'm just thinking off the cuff at the moment. Maybe there's some terminology that will help me find a tutorial. Any bit helps. thanks! I have made a Php program that downloads an Inno setup installation file for installing a program. However, if I for one or another reason want to make a new download of the same Inno setup installation file, the previous file will still be found in the Download folder. Each of the downloads get a number in parenthesis, setup(1), setup(2), setup(3) etc. However, I wondered if it is posible to erase the previous file in the same process as I download a new one, so that however many downloads I do, there will all the time only be one occurence of this file in the Download folder. The download code is as follows: $exe = "Inno script/Test_setup.exe"; header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"Test_setup.exe\""); header("Content-Length: " . filesize($exe)); readfile($exe); Thanks in advance. Sincerely
Hello I have a simple question about file handling... Is it possible to list all files in directories / subdirectories, and then read ALL files in those dirs, and put the content of their file into an array? Like this: array: [SomePath/test.php] = "All In this php file is being read by a new smart function!"; [SomePath/Weird/hello.txt = "Hello world. This is me and im just trying to get some help!";and so on, until no further files exists in that rootdir. All my attempts went totally crazy and none of them works... therefore i need to ask you for help. Do you have any ideas how to do this? If so, how can I be able to do it? Thanks in Advance, pros So far I have managed to create an upload process which uploads a picture, updates the database on file location and then tries to upload the db a 2nd time to update the Thumbnails file location (i tried updating the thumbnails location in one go and for some reason this causes failure) But the main problem is that it doesn't upload some files Here is my upload.php <?php include 'dbconnect.php'; $statusMsg = ''; $Title = $conn -> real_escape_string($_POST['Title']) ; $BodyText = $conn -> real_escape_string($_POST['ThreadBody']) ; // File upload path $targetDir = "upload/"; $fileName = basename($_FILES["file"]["name"]); $targetFilePath = $targetDir . $fileName; $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION); $Thumbnail = "upload/Thumbnails/'$fileName'"; if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){ // Allow certain file formats $allowTypes = array('jpg','png','jpeg','gif','pdf', "webm", "mp4"); if(in_array($fileType, $allowTypes)){ // Upload file to server if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ // Insert image file name into database $insert = $conn->query("INSERT into Threads (Title, ThreadBody, filename) VALUES ('$Title', '$BodyText', '$fileName')"); if($insert){ $statusMsg = "The file ".$fileName. " has been uploaded successfully."; $targetFilePathArg = escapeshellarg($targetFilePath); $output=null; $retval=null; //exec("convert $targetFilePathArg -resize 300x200 ./upload/Thumbnails/'$fileName'", $output, $retval); exec("convert $targetFilePathArg -resize 200x200 $Thumbnail", $output, $retval); echo "REturned with status $retval and output:\n" ; if ($retval == null) { echo "Retval is null\n" ; echo "Thumbnail equals $Thumbnail\n" ; } }else{ $statusMsg = "File upload failed, please try again."; } }else{ $statusMsg = "Sorry, there was an error uploading your file."; } }else{ $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, mp4, webm & PDF files are allowed to upload.'; } }else{ $statusMsg = 'Please select a file to upload.'; } //Update SQL db by setting the thumbnail column to equal $Thumbnail $update = $conn->query("update Threads set thumbnail = '$Thumbnail' where filename = '$fileName'"); if($update){ $statusMsg = "Updated the thumbnail to sql correctly."; echo $statusMsg ; } else { echo "\n Failed to update Thumbnail. Thumbnail equals $Thumbnail" ; } // Display status message echo $statusMsg; ?> And this does work on most files however it is not working on a 9.9mb png file which is named "test.png" I tested on another 3.3 mb gif file and that failed too? For some reason it returns the following Updated the thumbnail to sql correctly.Updated the thumbnail to sql correctly. Whereas on the files it works on it returns REturned with status 0 and output: Retval is null Thumbnail equals upload/Thumbnails/'rainbow-trh-stache.gif' Failed to update Thumbnail. Thumbnail equals upload/Thumbnails/'rainbow-trh-stache.gif'The file rainbow-trh-stache.gif has been uploaded successfully. Any idea on why this is? |