PHP - Id3 Tags And File Uploads
I'm looking for ideas thoughts that anyone might have regarding disappearing ID3 tags in .mp3 files after they are uploaded to a web server via $_FILES method.
In order, the steps occur at time of upload a 1) File upload is initiated 2) File is uploaded to temp dir on server 3) File is re-assigned a hash value for a file name, with .mp3 appended 4) File is moved from temp dir to the given users dir 5) Meta Data is supposed to be read, and a row inserted into the DB. Now, everything works as intended - not having any issues... Other than, of course, the mystery of the vanishing ID3 tags. Can anyone shed some light on this? I am 100% certain that I can read the meta data - giving two different parameters on two different files (one uploaded manually via sftp, the other via http through the use of $_FILES) Example of what's happening: http://69.164.222.60/test2.php nji.mp3 was uploaded via SFTP. The hashed .mp3 was uploaded via my web form. Thoughts / Comments / Suggestions / Ideas / Saving Grace? ^^ Similar TutorialsI am relatively new to PHP, so I need help why this script is not functioning **T if ($actionis=='Add Resource'){ //declaration of directory where files are saved if(isset($_POST['file'])) { //setting of variables $uploaddir = "resources/"; $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fileErr = $_FILES['userfile']['error']; $filePath= $uploaddir . basename($_FILES['userfile']['name']); global $filePath; //filters extension filename $fileX = strrchr($fileName,"."); /* * UPLOAD FILTERING OPTIONS */ if ($fileSize>1000000){ die ("File too large! Must be below 1Mb."); } else{ if (($fileX==".txt")||($fileX==".doc")||($fileX==".docx")||($fileX==".pdf")||($fileX==".ppt")||($fileX==".pptx")){ if (move_uploaded_file($_FILES['userfile']['tmp_name'], $filePath)){ echo "<code>SUCCESS! File Uploaded.</code> ".$fileErr; } else{ echo "<code class='red'>Upload Failed.</code>"; } } else{ die ("Wrong file format!"); } } } The above script does not generate an error. But my problem is that I cannot save the uploaded file into my selected directory. My goal is to allow the user to select whether or not they want to replace the current img files. If so delete all current ones in select dir and upload into it. If not then began uploading at a specific point such that. 1.jpg 2.jpg 3.jpg ... and so on (replace yes deletes all and no deletes none) The directories are assigned previously and are accessed via sql database These are the two current sets i have <?php $page_title = "Central Valley LLC | Photo Addition" ?><?php include("header.php"); ?><?php include("nav.html"); ?> <div id="content"> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="which">Choose A Product:</label> <?php $con = mysql_connect("localhost","phoenixi_cv","centraladmin"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("phoenixi_cvproducts", $con); $result = mysql_query("SELECT * FROM Products"); echo "<select>"; while($row = mysql_fetch_array($result)) { echo "<option "; echo "value=\"" . $row['num'] . "\">"; echo $row['Name'] . "</option>"; } echo "</select>"; mysql_close($con); ?> <br /> <h3 id="center">Do You Wish To Replace Current Images?</h3> <br /> <input type="radio" name="replace" value="y" />YES<br /> <input type="radio" name="replace" value="n" />NO <br /> <input name="uploads[]" type="file" multiple="multiple" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </div><!--#content--><?php include("footer.html") ?>() and this is the upload script so far <?php $count = 1; if($_POST[replace]=='y') { $mydir = 'assets/images/' . $_POST['which'] . '/'; $d = dir($mydir); while($entry = $d->read()) { if($entry!="." && $entry!="..") { unlink($entry); } } } else { $loop = true; while($loop == true) { $filename = 'assets/images/' . $_POST['which'] . '/' . $count . '.jpg'; if(file_exists($filename)) { $count++; } else { $loop = false; } } } if(!is_dir("uploads/".$id)) { //this checks to make sure the directory does not already exist mkdir("uploads/".$id, 0777, true); //if the directory doesn't exist then make it chmod("uploads/".$id, 0777); //chmod to 777 lets us write to the directory } $uploaddir = 'assets/images/' . $_POST['which'] . '/'; foreach($_FILES["uploads"]["name"] as $bla=> $boo) { //we have to do a loop to get all the filenames $file=$uploaddir.$boo; //we will check the filename in the upload directory, see if it exists if (file_exists($file)) { //if it exists then ...... die("Filename already exists, please rename this file"); //if filename exists in the directory then we die!!! :P } } foreach ($_FILES["uploads"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { echo"$error_codes[$error]"; // let you know if there was an error on any uploads move_uploaded_file( //php function to move the file $_FILES["uploads"]["tmp_name"][$key], //from the temporary directory $uploaddir. $_FILES["uploads"]["name"][$key] //to the directory you chose ) or die("Problems with upload"); } } foreach($_FILES["uploads"]["name"] as $bla=> $boo) { $file=$uploaddir.$boo; $movepoint = $uploaddir . $count . '.jpg'; rename($file, $movepoint); $count++; } ?>() Thanks in advance for any help that you can give me.Also if you can suggest any easier ways i would certainly be obliged. This doesn't seem to be working. Any help? if (isset ($_POST['edit_poser'])){ $errormsg = ""; if (!$_FILES['userfile']['tmp_name']){ $errormsg = "<font style='color: #ff0000;'>Select an Image</font>"; } else { $maxfilesize = 51200; if ($_FILES['userfile']['size'] > $maxfilesize){ $errormsg = "<font style='color: #ff0000;'>Image is too large, select a smaller one</font>"; unlink($_FILES['userfile']['tmp_name']); } else if (!preg_match("/\.(gif|jpg|png)$/i" , $_FILES['userfile']['name'])){ $errormsg = "<font style='color: #ff0000;'>Image needs to be gif, jpg, or png</font>"; unlink($_FILES['userfile']['tmp_name']); } else { $newname = "image01.jpg"; $place_file = move_uploaded_file($_FILES['userfile']['tmp_name'], "Members/$id/".$newname); $errormsg = "<font style='color: #ff0000;'>Your image has successfully been updated</font>"; } } } // ends first if statement Hey everyone. I have a form that is working fine. Basically it will upload files to an email address. The files do arrive at the email address, but the problem is that they show up as 0KB in my inbox. Photos, text docs etc., that I upload via the form are arriving in my email at 0KB for some reason. I know the code is messy, but hopefully someone can figure out why the files are uploading as 0KB. **Please see attached code Hi, I want to let users upload multiple images to my online picture book, so after they press submit, HOW do I count the total $_FILES[someName]['name'] uploaded. I want to allow users to type in html form the total uploads they want and this will then display that many desired upload forms. I'm going to try count($_FILES[][]) and go from there first... Any help much appreciated! I have a form that lets a user upload an image, aswell as another file. I want the image to go into the images directory, and the pdf file to go into the PDF directory once uploaded. The names of the files will then be uploaded to the database. At the moment I can get the image to upload to the database and directory, but the PDF is only uploading the name to the database, it is not going into the PDF directory aswell. I'm not sure if there is a way you can do this, I am trying to use "move_uploaded_file()" to physically move the files but not sure if you can use it twice. here is my code, if you can point anything out or where im going wrong that would be great. <?php include "include/conn.php"; include "include/session.php"; ?> <?php // Check to see if the type of file uploaded is a valid image type function is_valid_type($file) { $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif"); if (in_array($file['type'], $valid_types)) return 1; return 0; } function showContents($array) { echo "<pre>"; print_r($array); echo "</pre>"; } //Target path for image $TARGET_PATH = dirname(__FILE__) . "/images/"; //Target path for PDF files $PDF_TARGET_PATH = dirname(_FILE_) . "/PDF/"; // Get POST variables $image = $_FILES['image']; $pdf = $_FILES['pdf']; $date= date("Y-m-d "); $time = date("H:i:s"); $title = $_POST['title']; $title_escape = mysql_escape_string($title); $title_slashes = stripslashes($title_escape); $content = $_POST['content']; $image['name'] = mysql_real_escape_string($image['name']); $pdf['name'] = mysql_real_escape_string($pdf['name']); //image path $TARGET_PATH .= $image['name']; //PDF path $PDF_TARGET_PATH .= $pdf['file_name']; // Make sure all the fields from the form have inputs if ($image['name'] == "" ) { $_SESSION['error'] = "All fields are required"; header("Location: add_media.php"); exit; } // Verify file is an image if (!is_valid_type($image)) { $_SESSION['error'] = "You must upload a jpeg, gif, or bmp"; header("Location: add_media.php"); exit; } // move file into the directory and the path name into the database / along with the rest of the form fields if (move_uploaded_file($image['tmp_name'], $TARGET_PATH)) { if(move_uploaded_file($pdf['tmp_name'], $PDF_TARGET_PATH)) { $sql = "INSERT INTO media_table(title, text, time, date, image, PDF) VALUES ('" . $title_slashes . "','" . $content . "', '" . $time . "', '" . $date . "', '" . $image['name'] . "', '" . $pdf['name'] . "')"; $result = mysql_query($sql) or die (mysql_error()); header("Location: add_media.php"); exit; } else { print "did not upload"; } } else { $_SESSION['error'] = "Could not upload file. Check read/write persmissions on the directory"; exit; } ?> Hello. My script is set to upload files upto 5GB large. For that script I've currently set memory_limit to 5GB. Is it alright? I mean what is the ideal value (for large upload scripts) If you feel, 5GB is large. I can make script to upload 2GB files and set memory_limit accordingly. Also, max_execution_time has been set by me to 86400 currently. Assuming, on a 500Kbps broadband, it would require upto 24 hours to upload a 3-5GB file. Please suggest. Thank you. Awhile ago I wrote a simple form to except image specific uploads from users and chmoded the directory to 777... worked great... Till there was a hack and then I found that chmod 777 is bad So changed the folder to 775, but now the upload script won't work. Can somebody point me to a post or article on how to give a file ownership or group permissions so it can safely run its uploads to the folder? I have tried google but keep getting Linux and Window OS results.. its a tough question to google. Any help is very much appreciated. I've got a typical form with an input type="file" for users to upload photos to my site (2mb max to be exact). If you view my code below, you'll notice that I set a variable as the uploaded file's size, and a variable for the max file size I want in bytes. When making sure that the uploaded file's size is LESS than the limit size I set, it should push an error. However, I've noticed that my variable $uploadSize that is supposed to grab the upload file size is only returning "0" (zero). I've tried var_dump($_FILES) to see what was going on and it shows the array with the proper name of the uploaded file, etc. but the file size returns 0. So any file size I upload will bypass my test to see if the file size is less than the limit size. I've tested uploading images 2mb or less and the photos have successfully been queried, moved and resized. However, if I try and upload images LARGER than 2mb, the form still queries all the inputted data into the database but the image isn't successfully moved. I've used this same form and approach on a previous project and I didn't have any trouble. Can I get your guys' eyes on this and see if I'm missing anything small? Code: [Select] <?php if(isset($_POST['submit'])){ // ------------------------------------------------------------- // // A. SET VARIABLES // A1. set variables for inputted data $first = filter_var($_POST['first'], FILTER_SANITIZE_STRING); $last = filter_var($_POST['last'], FILTER_SANITIZE_STRING); $email = filter_var($_POST['email'], FILTER_SANITIZE_STRING); $email2 = filter_var($_POST['email2'], FILTER_SANITIZE_STRING); $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING); $description = filter_var($_POST['description'], FILTER_SANITIZE_STRING); // A2. set variables for uploaded submission $uploadPath = $_FILES['uploadFile']['tmp_name']; $uploadSize = $_FILES['uploadFile']['size']; $uploadLimit = 2097152; /* 2mb max file size */ // A3. create error array $errors = array(); // ------------------------------------------------------------- // // B. VALIDATE FIELDS // B1. validate required fields if (empty($first)){ array_push($errors, 'first'); } if (empty($last)){ array_push($errors, 'last'); } if (empty($email)){ array_push($errors, 'email'); } if (empty($email2)){ array_push($errors, 'email2'); } if (empty($name)){ array_push($errors, 'name'); } // B2. validate emails if ($email != $email2){ array_push($errors, 'emailmismatch'); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)){ array_push($errors, 'invalidemail'); } // B3. validate uploaded image file size if ($uploadSize > $uploadLimit){ array_push($errors, 'filesize'); } // ------------------------------------------------------------- // // if no errors, continue query if (sizeof($errors) == 0){ // continue query } } ?> Code: [Select] <form method="post" enctype="multipart/form-data" id="submit-form"> <label for="first">First Name:</label> <input name="first" type="text" value="<?php echo $first; ?>"<?php if(in_array('first', $errors)){ echo ' class="error"'; } ?>> <label for="last">Last Name:</label> <input name="last" type="text" value="<?php echo $last; ?>"<?php if(in_array('last', $errors)){ echo ' class="error"'; } ?>> <label for="email">Email Address:</label> <input name="email" type="text" value="<?php echo $email; ?>"<?php if(in_array('email', $errors)){ echo ' class="error"'; } else if (in_array('emailmismatch', $errors)){ echo ' class="error"'; } ?>> <label for="email2">Confirm Email Address:</label> <input name="email2" type="text" value="<?php echo $email2; ?>"<?php if(in_array('email2', $errors)){ echo ' class="error"'; } else if (in_array('emailmismatch', $errors)){ echo ' class="error"'; } ?>> <br><br><br><br> <label for="name">Your Photo Name:</label> <input name="name" type="text" value="<?php echo $name; ?>"<?php if(in_array('name', $errors)){ echo ' class="error"'; } ?>> <label for="description">Describe The Photo: <span class="optional">(optional)</span> <div class="right"><span class="optional">300 characters max</span></div></label> <textarea name="description" onKeyDown="limitInput(this.form.description,this.form.countdown,300);" onKeyUp="limitInput(this.form.description,this.form.countdown,300);"><?php echo stripslashes($description); ?></textarea> <label for="upload">Photo Image: <span class="optional">(.JPG's only, max 2mb file size)</span></label> <input type="hidden" name="MAX_FILE_SIZE" value="2097152"> <input id="uploadFile" name="uploadFile" type="file"<?php if(in_array('badimage', $errors)){ echo ' class="error"'; } ?> /> <input type="submit" name="submitFeature" class="submit" value="Submit Your Feature"> </form> Hi Have got my form working for all standard bits. Just need to add the functionality for people to upload photos. I copied and modified the form from a site and there is a section that I think is redundant it still works when I comment it out can you clarify for me: Code: [Select] // validation expected data exists /* if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } */ Below is the full code for the form: Code: [Select] <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "asdfasdf@asdfasdf.com"; $email_subject = "adsfasdf asdfasdf Application Form"; function died($error) { // your error code can go here ?> <title>asdfas asdfasd</title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF" onLoad="setTimeout('history.back()',10000)"> <p><img src="../images/logo.png" width="326" height="144" alt="asdfasdf" longdesc="http://www.adsfasdf.com" /><br /> </p> <br /> <p>We are very sorry, but there were error(s) found with the form you submitted.</p> <p>Please fix the following errors:</p> <hr /> <br /> <?php echo $error; ?> <hr /> <br /> <p>Click back to fix your error(s) or you will be taken back to the form automatically in 10 seconds...</p> <h6> </h6> <h6>© asdfasdf 2012</h6> </body> </html> <?php die(); } // validation expected data exists /* if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } */ $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $age = $_POST['age']; $city = $_POST['city']; $state = $_POST['state']; $height_feet = $_POST['height_feet']; $height_inches = $_POST['height_inches']; $error_message = ""; $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'First Name: This is not a valid name.<br /><br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'Last Name: This is not a valid last name.<br /><br />'; } $age_exp = "/^(1[89]|[2-9][0-9])$/"; if(!preg_match($age_exp,$age)) { $error_message .= 'Age: You need to be at least 18+ to apply.<br /><br />'; } $phone_exp = "/^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/"; if(!preg_match($phone_exp,$telephone)) { $error_message .= 'Phone: eg 646 555 1234 or 646-555-1234 or (646) 555 1234<br /><br />'; } $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'Email: Your address is not invalid eg yourname@emaildomain.com<br /><br />'; } if(strlen($comments) < 2) { $error_message .= 'Comments: Please leave a breif message explaining your interest and if you have any previous experience etc.<br /><br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below:\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name:"."\t".clean_string($first_name)."\n"; $email_message .= "Last Name:"."\t".clean_string($last_name)."\n"; $email_message .= "Age:"."\t".clean_string($age)."\n"; $email_message .= "Height:"."\t".clean_string($height_feet).'ft ' . clean_string($height_inches).'in'."\n"; $email_message .= "City:"."\t".clean_string($city)."\n"; $email_message .= "State:"."\t".clean_string($state)."\n"; $email_message .= "Email:"."\t".clean_string($email_from)."\n"; $email_message .= "Telephone:"."\t".clean_string($telephone)."\n"; $email_message .= "Comments:"."\t".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> <title>adsfas asdfasdf</title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF" onLoad="setTimeout('history.back()',10000)"> <p><img src="../images/logo.png" width="326" height="144" alt="asdfasdf" longdesc="http://www.asdfasdf.com" /><br /> </p> <p>Thank your for applying to asdf adsf. We will be in touch with you very soon.</p> <p>You will be redirected back to the site in 10 seconds...</p> <h6> </h6> <h6>© adsfdasf 2012</h6> </body> </html> <?php } ?> Here is the html form: Code: [Select] <form id="form2" action="./php/joinus.php" method="post" enctype="multipart/form-data"> <fieldset> <div class="wrapper"> <div class="fleft col"> <label class="first_name"> <span class="text-form">Name:</span> <input name="first_name" type="text" value=""> </label> <label class="age"> <span class="text-form">Age:</span> <input name="age" type="tel" value=""> </label> <label class="city"> <span class="text-form">City:</span> <input name="city" type="text" value=""> </label> <label class="telephone"> <span class="text-form">Phone:</span> <input name="telephone" type="tel" value=""> </label> </div> <div class="fleft col2"> <label class="last_name"> <span class="text-form">Last Name:</span> <input name="last_name" type="text" value=""> </label> <span id="validate_height"> <label><span class="text-form">Height:</span> <select style="width:109px;" name="height_feet"> <option value="" selected="selected">Feet</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> <select style="width:109px;" name="height_inches"> <option value="" selected="selected">Inches</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> </select> </label> </span> <label class="state"> <span class="text-form">State:</span> <select name="state"> <option value="" selected="selected">Select a State</option> <option value="Alabama">Alabama</option> <option value="Alaska">Alaska</option> <option value="Arizona">Arizona</option> <option value="Arkansas">Arkansas</option> <option value="California">California</option> <option value="Colorado">Colorado</option> <option value="Connecticut">Connecticut</option> <option value="Delaware">Delaware</option> <option value="District Of Columbia">District Of Columbia</option> <option value="Florida">Florida</option> <option value="Georgia">Georgia</option> <option value="Hawaii">Hawaii</option> <option value="Idaho">Idaho</option> <option value="Illinois">Illinois</option> <option value="Indiana">Indiana</option> <option value="Iowa">Iowa</option> <option value="Kansas">Kansas</option> <option value="Kentucky">Kentucky</option> <option value="Louisiana">Louisiana</option> <option value="Maine">Maine</option> <option value="Maryland">Maryland</option> <option value="Massachusetts">Massachusetts</option> <option value="Michigan">Michigan</option> <option value="Minnesota">Minnesota</option> <option value="Mississippi">Mississippi</option> <option value="Missouri">Missouri</option> <option value="Montana">Montana</option> <option value="Nebraska">Nebraska</option> <option value="Nevada">Nevada</option> <option value="New Hampshire">New Hampshire</option> <option value="New Jersey">New Jersey</option> <option value="New Mexico">New Mexico</option> <option value="New York">New York</option> <option value="North Carolina">North Carolina</option> <option value="North Dakota">North Dakota</option> <option value="Ohio">Ohio</option> <option value="Oklahoma">Oklahoma</option> <option value="Oregon">Oregon</option> <option value="Pennsylvania">Pennsylvania</option> <option value="Rhode Island">Rhode Island</option> <option value="South Carolina">South Carolina</option> <option value="South Dakota">South Dakota</option> <option value="Tennessee">Tennessee</option> <option value="Texas">Texas</option> <option value="Utah">Utah</option> <option value="Vermont">Vermont</option> <option value="Virginia">Virginia</option> <option value="Washington">Washington</option> <option value="West Virginia">West Virginia</option> <option value="Wisconsin">Wisconsin</option> <option value="Wyoming">Wyoming</option> </select> </label> <label class="email"> <span class="text-form">E-mail:</span> <input name="email" type="text" value=""> </label> </div> </div> <label class="message"> <span class="text-form">Comments:</span> <textarea name="comments"></textarea> </label> <label> <span class="text-form2">Attach a photo:</span> <input id="photo" name="file[]" type="file" class="fl" > </label> <label> <span class="text-form2">Attach a photo:</span> <input id="photo" name="file[]" type="file" class="fl" > </label> <label> <span class="text-form2">Attach a photo:</span> <input id="photo" name="file[]" type="file" class="fl" > </label> <div class="but"><a class="link1 link-color2" data-type="submit" onClick="document.getElementById('form2').submit()">Submit</a></div> </fieldset> </form> From what I've been reading you need to tell the php to put it to a temporary file from the submit.. then move it to the file name and then somehow include that file name in the php email back. So maybe a url and its private or htaccess? or does it get included as attachment in the mail? Im not sure if i should be using 'id' or 'name' in the html form etc and how to tie it together. Any help or guides much appreciated. Thanks Wolfsta This upload code is used for uploading a video file from html page, after recording via html5 screen <video></video>, however, ther file doesn't arrive in the uploads/ folder:
<?php foreach (array('video', 'audio') as $type) { if (isset($_FILES["${type}-blob"])) { $fileName = $_POST["${type}-filename"]; $uploadDirectory = 'uploads/' .rand(5,500).$fileName; if (!move_uploaded_file($_FILES["${type}-blob"]["tmp_name"], $uploadDirectory)) { echo (" problem moving uploaded file"); } } } when uploaded from iPhone. So, I don't know how to see errors on iPhone. Folder permission is 755. php.ini max file size is 2024M, any ideas/solutions are appreciated.
I have a file upload script that will eventually process a ton of files. I would like to upload them into sub-directories according to what year, month, and day they are uploaded.
A typical tree should look like this:
attachments/
--/2014
-----/January
--------/01
--------/02
--------/03 , etc.
-----/February
--------/01
--------/04
--------/09
--------/18
--------/20, etc
-----/March, etc
--/2015, etc.
So a file called image.jpg uploaded on 10/31/2014 would have a URL of attachments/2014/October/31/image.jpg. I understand that every time a file is uploaded, the script would have to detect through FTP whether or not folders for the year, month, and day exist, and if they don't create them. My problem is that I have no idea what the logic of this script would be. What order should I do things in? Is there a way to use maybe foreach to detect/create the folders? Any input would be appreciated.
Stumped! I have a client who has a form where they upload files to their server: title, two password fields, and the file
They have been unable to upload anything over 10m
Small (under 10mb) files work.
Larger doesn’t
I’ve tracked it down, I think, that the processing page appears to be dropping the form values when the file takes a bit to upload.
I echo’ed the values that are grabbed from the form, and they return empty strings if it takes a while for the file to upload (a large file) - they pass fine if the file is smaller.
I think I've got the php info set correctly, but cannot for the life of me figure out how to adjust the timing out issue, or even where to troubleshoot.
Here's my phpinfo:
Max Requests
Per Child: 750 - Keep Alive: off - Max Per Connection: 100
Timeouts
Connection: 120 - Keep-Alive: 5
Directive
Local Value
Master Value
allow_call_time_pass_reference
Off
Off
allow_url_fopen
On
On
allow_url_include
Off
Off
always_populate_raw_post_data
Off
Off
arg_separator.input
&
&
arg_separator.output
&
&
asp_tags
Off
Off
auto_append_file
no value
no value
auto_globals_jit
On
On
auto_prepend_file
no value
no value
browscap
/etc/browscap.ini
/etc/browscap.ini
default_charset
no value
no value
default_mimetype
text/html
text/html
define_syslog_variables
Off
Off
disable_classes
no value
no value
disable_functions
leak,posix_getpwuid,posix_getpwnam,posix_getgrid,posix_getgrnam,posix_getgroups
leak,posix_getpwuid,posix_getpwnam,posix_getgrid,posix_getgrnam,posix_getgroups
display_errors
Off
Off
display_startup_errors
Off
Off
doc_root
no value
no value
docref_ext
no value
no value
docref_root
no value
no value
enable_dl
Off
Off
error_append_string
no value
no value
error_log
/mnt/Target01/337846/945285/www.dermerrealestate.com/logs/php_errors.log
no value
error_prepend_string
no value
no value
error_reporting
30711
30711
exit_on_timeout
Off
Off
expose_php
Off
Off
extension_dir
/usr/lib64/php/modules
/usr/lib64/php/modules
file_uploads
On
On
highlight.bg
#FFFFFF
#FFFFFF
highlight.comment
#FF8000
#FF8000
highlight.default
#0000BB
#0000BB
highlight.html
#000000
#000000
highlight.keyword
#007700
#007700
highlight.string
#DD0000
#DD0000
html_errors
On
On
ignore_repeated_errors
Off
Off
ignore_repeated_source
Off
Off
ignore_user_abort
Off
Off
implicit_flush
Off
Off
include_path
.:/usr/share/pear:/usr/share/php
.:/usr/share/pear:/usr/share/php
log_errors
On
On
log_errors_max_len
1024
1024
magic_quotes_gpc
On
On
magic_quotes_runtime
Off
Off
magic_quotes_sybase
Off
Off
mail.add_x_header
On
On
mail.force_extra_parameters
no value
no value
mail.log
no value
no value
max_execution_time
30
30
max_file_uploads
20
20
max_input_nesting_level
64
64
max_input_time
60
60
max_input_vars
1000
1000
memory_limit
128M
128M
open_basedir
no value
no value
output_buffering
no value
no value
output_handler
no value
no value
post_max_size
8M
8M
precision
14
14
realpath_cache_size
4M
4M
realpath_cache_ttl
120
120
register_argc_argv
On
On
register_globals
Off
Off
register_long_arrays
On
On
report_memleaks
On
On
report_zend_debug
On
On
request_order
no value
no value
safe_mode
Off
Off
safe_mode_exec_dir
no value
no value
safe_mode_gid
Off
Off
safe_mode_include_dir
no value
no value
sendmail_from
no value
no value
sendmail_path
/usr/sbin/sendmail -t -i
/usr/sbin/sendmail -t -i
serialize_precision
100
100
short_open_tag
On
On
SMTP
localhost
localhost
smtp_port
25
25
sql.safe_mode
Off
Off
track_errors
Off
Off
unserialize_callback_func
no value
no value
upload_max_filesize
8M
8M
upload_tmp_dir
/tmp
/tmp
user_dir
no value
no value
user_ini.cache_ttl
300
300
user_ini.filename
.user.ini
.user.ini
variables_order
EGPCS
EGPCS
xmlrpc_error_number
0
0
xmlrpc_errors
Off
Off
y2k_compliance
On
On
zend.enable_gc
On
On
Hello again:] I am wondering where should i put valid doctype <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> and meta tags <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> in a php file like this. Code: [Select] <?php session_start(); // Session starts here if(!isset($_SESSION['username'])) // If there is no session then... { die ("<div align='center'><img src='images/LOGINKITTEN.jpg'/><br /><a href='index.php'><img src='images/Login.jpg'/></a></div>"); // ...Die! } $id = $_GET['id']; ?> <html> <head> <link rel="stylesheet" type="text/css" href="jamcss.css" /> </head> <body> <img src="images/jamspace.jpg" /> <div id="jamcontainer"> <b><a href="main.php">Home</a> || <a href="members.php">Members</a> || <a href="jams.php">Jams</a> || <a href="uploadjamform.php">Upload Jam</a> || <a href="myprofile.php">My profile</a> || <a href="about.php">About</a> || <a href="adminindex.php">Moderators</a> || <a href="logout.php">Logout</a></b> You are logged in as <?php echo $_SESSION['username']; ?> <br /><br /> <?php $connection = mysql_connect("lol.com", "loldb", "lol00") or die ("Could not connect"); mysql_select_db("loldb", $connection) or die("Could not connect"); // mysql query to get the username $query = mysql_query("SELECT * FROM news ORDER BY id DESC"); $numrows = mysql_num_rows($query); if ($numrows!=0) { // fetching data from the database to variable while ($row = mysql_fetch_assoc($query)) { $title = $row['title']; $post_owner = $row['post_owner']; $post = $row['post']; echo "<b>" . $title . "</b><br />"; echo "Posted by <b>" . $post_owner . "</b><br /><br />"; echo $post . "<hr></hr><br /><br />"; } } ?> </div> </body> </html> Yes, it's a homework assignment. No, I'm not trying to cheat, so pointing me somewhere is better than just feeding me code, like, "look up how to blah blah" or tell me what I've got wrong? I'm trying to parse a text file of the constitution, add header and <p> tags depending on the first word of the paragraph, then print to an html page. I know I'm supposed to create a function that will return a paragraph, and another function that will return the first word of a paragraph. This is my code, and it completely does not work (obviously I've not included the external html tags) <?php // Opens the constitution text file. $const = fopen("constitution.txt","r"); //Returns an entire paragraph function getParagraph($myfile) { while (!feof($myfile)){ $line = file_get_contents($myfile); $paragraph = explode("\n",$line); } return $paragraph; } //Returns the first word of a paragraph function getFirstWord($myfile) { $pg = getParagraph($myfile); $word = explode(" ",$pg); Return $word[0]; } // Runs through some if statements to determine the tags to use if (getFirstWord($const) === "Article"){ echo "<h2> getParagraph($const)</h2>"; } elseif (getFirstWord($const) === "Section"){ echo "<h3> getParagraph($const)</h3>"; } elseif (getFirstWord($const) === "Amendment"){ echo "<h3> getParagraph($const)</h3>"; } elseif (getFirstWord($const) === "We the People"){ echo "<em> getParagraph($const) </em>"; } else{ echo "<p> getParagraph($const) </p>"; } fclose($const); ?> Hey Guys. I am trying to write to an HTML and attach that file for an efax API. One of the file types they accept is HTML, but it has to be in a <base> tag format. I am a little confused on how to do that. I tried to use fopen with the base tag but it didn't seem to work for me. I got the following error
Warning: fopen(<base a href='96401.html'></base>) [function.fopen]: failed to open stream: No such file or directory
Ideally what I am trying to accomplish is creating a file that just says 96401.html.
Below is the code that I have tried it with. Any help would be really appreciated!!!
$orderFile = "<base a href='".$id.".html'></base>"; // File name to be created. order id is used as a file name e.g. 123456.html //$fh = fopen($orderFile, 'w') or die("can't open file"); // Create and Save the writeable File //fwrite($fh, $order_information); // Write email contents to created file. Hi Still very new to PHP but getting some good use out of it with includes. I'm currently using this code to check the file name of the page and then give the corresponding anchor tag a class of active in order to style my main menu. This is all working for most of my pages but my problem is that I now have multiple files called index.php one in the root of my site and some are in folders. Is there any way around this issue? Can PHP check to see if its the index file in the root of the site or is there a better way. I suppose I could create a second variable in the index file in my root ie my home page and then check to say if the current page is called index and has the variable of home but how would I write this? My code Code: [Select] $currentPage = basename($_SERVER['SCRIPT_NAME'], '.php'); <li><a href="/" <?php if ($currentPage == 'index') {echo 'class="active"';} ?>>Home</a></li> hi everyone, did not know what to make the subject, but here is what I want to do: I have a string, which gets returned to me from a linux app on my server, it looks something like this: Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8"> <TITLE> </TITLE> <META NAME="GENERATOR" CONTENT="OpenOffice.org 3.2 (Linux)"> <META NAME="AUTHOR" CONTENT="Administrator"> <META NAME="CREATED" CONTENT="20110106;14170000"> <META NAME="CHANGEDBY" CONTENT="HOD"> <META NAME="CHANGED" CONTENT="20110522;16540000"> <STYLE TYPE="text/css"> <!-- @page { margin: 0.26in } P { margin-bottom: 0.15in; direction: ltr; color: #000000; line-height: 0.15in; text-align: justify; widows: 2; orphans: 2 } P.western { font-family: "Arial", sans-serif; font-size: 10pt; so-language: en-US } P.cjk { font-family: "Batang", "바탕", serif; font-size: 10pt } P.ctl { font-family: "Times New Roman", serif; font-size: 10pt; so-language: ar-SA } A:link { color: #0000ff } --> </STYLE> </HEAD> <BODY LANG="en-US" TEXT="#000000" LINK="#0000ff" DIR="LTR" STYLE="border: 5.05pt double #000000; padding: 0.67in 0.92in"> <P>I want this and the tags around it, just not the html, head, body and their closing tags.</P> </BODY> </HTML> within the body, the tags are each styled for example: <p style="color: red"></p> so I cannot just get rid of all html, I want to get only all the content within the body tags, but without the body tags obviously strip_tags does not work as i need, I only want to strip certain tags. If someone can help me with this i will much appreciate it. Hey guys, I'm a total newbie here, and just about as a new to php. My issue: I have a very large .html file that contain multiple articles (I actually have a few of these, but we'll start with one for practicality). The article titles are all wrapped in <h2> tags, there are 10 articles in one file. The articles are very simple, just a title wrapped with <h2> and then a few paragraphs wrapped in <p> tags. What I want to know how to do: I want to know if there's a way to open that file, and have each article saved as it's own .html or .txt document (the title & following paragraphs of each article). Ultimately taking my 1 large file, and creating the subsequent 10 smaller files from the articles inside of it. I am having trouble explaining this in text so I'll try to illustrate: I have "Articles.html" - which contains (article1,article2,article3.. ..article10) I want to split "Articles.html" and create "Article1.html", "Article2.html", "Article3.html", etc. Is that possible? Or am I looking at something far more complex than I can imagine at this point - perhaps something I'd be better off doing by hand? Ultimately I intend to stick all these articles into a database, but that's the 2nd part of what I want to do (and I think will be the easier of the tasks). Let me know if you need any additional information in the event my description above is unclear... I simply am having issues figuring out how to separate out the text into individual articles. I need some quick help with this, This is my file upload row loop, I want to add the if <b>k = 4</b>, then you have reached the maximum upload. Or something to that Effect. PRetty much only allowing 4-upload per user, before stoping the upload feature.. row count Code: [Select] <?php $k = 4; //$n=5; for ($i=0, $n=count( $this->songs ); $i < $n; $i++) //for ($i=0, $n=count( $this->songs ); $i < $n; $i++) { $song = &$this->songs[$i]; $checked = JHTML::_('grid.id', $i, $song->id ); $link_edit = JRoute::_( 'index.php?userid='.$this->xxx->user_id.'&layout=form&id=' . $song->id .'&from=xxx'); $tick = JHTML::image("images/tick.png",JText::_('Yes')); $tick_file = JHTML::image("images/tick.png",JText::_('Yes'),array("title" => $xxx->filename)); $cross = JHTML::image("images/publish_x.png",JText::_('No')); ?> End row count Code: [Select] <?php $k = 1 - $k; } ?> |